#include "tinyxml/tinyxml.h"
#include "XmlDataManager.h"
#include "StringConverter.h"
#include "NGLog.h"
#include "GameDefine.h"
#include LOG_MGR_PATH
#include LOGIC_MGR_PATH
#include "NoticeManager.h"
#include "GameStruct.h"
#include "Tools.h"

using std::map;
using std::list;

bool compareRobotCharid(stDDZRobot stDR1, stDDZRobot stDR2)
{
	if(stDR1.char_id > stDR2.char_id)
		return true;
	
	return false;
}

//--------------------------------------------------------
XmlDataManager::XmlDataManager()
{
#ifdef _USE_DEFAULT_XML_DATA_MGR_
// 如果有自定义配置管理器,宏定义内的代码不执行	
	LoadJackerooHortation();	
#endif
	LoadLoginGift();
	LoadGameConfig();
	LoadGZIDName();	
	LoadSMGameConfig();
	LoadServerIP();
	LoadMailModel();
	LoadCommonConfig();
	InitLevelExpList();
	LoadGameIDXml();
	LoadChanceConf();	
	LoadWebLevelConf();
	LoadViproomNeedcoins();
	LoadMaJonMissionXml();
	LoadBuyLargessXml();
	LoadGiveLeCardsXml();
	LoadFruitXml();
	LoadWealthTitle();
	LoadSystemNotices();
	LoadItemSetConfig();
	LoadHappyFarm();
	LoadCommonOrderXml();
	LoadGameNameXml();
	LoadCenterBattleOpenCoinsXml();
	LoadGameIdsXml();
	LoadCenterBattleModeXml();
	LoadCenterJudgeLabelIDXml();
	LoadBuyUnionGoodsXml();
	LoadCommonOnlineGiftXml();
	LoadGatewayResonXml();
	LoadItemModelNameXml();
	LoadRegisterGiveItemsXml();
	LoadCenterMatchModeInfo();
	LoadCommonActivity();
	LoadCommonSignInfoXml();
	LoadBuildEffortsXml();
	LoadGatewayHttpHoseAddr();
	LoadMatchOrderScoreXml();
	LoadDDZRobotXml();
	LoadPuKePublicDataXml();
}

//--------------------------------------------------------
XmlDataManager::~XmlDataManager()
{
	// 释放内存
	// map<uint32, CastFlow*>::iterator iter = m_mapDDZFlows.begin(), iterEnd = m_mapDDZFlows.end();
	// for (; iter != iterEnd; ++iter)
	// {
		// delete iter->second;
	// }
	
	// m_mapDDZFlows.clear();
}
//等级--------------------------------
bool XmlDataManager::InitLevelExpList()
{
	char strPath[512] = "";
	sprintf(strPath, "%s/levels.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	
	if(!doc.LoadFile())
	{
		Log.Error("load level and exp", "load levelexp.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load level and exp", "levelexp.xml have not root node!");
		return false;
	}
	if (String(pRoot->Value()).compare("levels"))
	{
		Log.Error("load level and exp", "levelexp.xml's root node is error!");
		return false;
	}
	TiXmlElement* pChild = pRoot->FirstChildElement();
	while(pChild != NULL)
	{
		uint8 level = atoi(pChild->Attribute("lv"));
		uint32 exp = atoi(pChild->Attribute("exps"));
		m_mapLevelExp.insert(std::make_pair(level, exp));
		pChild = pChild->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::InitLevelExpList:", "load levels.xml successfully! m_mapLevelExp[%u]", m_mapLevelExp.size());
	return true;
}

//--------------------------------------------------------
const uint32 XmlDataManager::GetExpsOfLevel(const uint8 level) const
{
	WGS_XML_READ_LOCK
	map<uint8, uint32>::const_iterator iter = m_mapLevelExp.find(level);
	if (iter != m_mapLevelExp.end())
		return iter->second;
	return 0;
}
///游戏的一些配置 比如时间///StarX///////////////////////////
bool XmlDataManager::LoadGameConfig(void)
{
	char strPath[512] = "";
	sprintf(strPath, "%s/game_conf.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/game_conf.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load game_conf.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "game_conf.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager init", "Start load %s", strPath);
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		String szName = child->Attribute("name");
		uint32 val = StringConverter::parseUnsignedInt(child->Attribute("value"));
		m_mapGameConfig.insert(std::make_pair(szName, val));
		child = child->NextSiblingElement();
	}
	
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReloadGameConfig(void)
{
	WGS_XML_WRITE_LOCK
	ReloadCommonConfig();
	m_mapGameConfig.clear();
	return LoadGameConfig();
}

//--------------------------------------------------------
bool XmlDataManager::LoadCommonConfig(void)
{
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/common.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load common.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "common.xml have not root node!");
		return false;
	}
	
	// Log.Debug("XmlDataManager init", "Start load %s", strPath);
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		String szName = child->Attribute("name");
		uint32 val = StringConverter::parseUnsignedInt(child->Attribute("value"));
		m_mapCommConfig.insert(std::make_pair(szName, val));
		child = child->NextSiblingElement();
	}
	
	return true;
}

//--------------------------------------------------------
bool XmlDataManager::ReloadCommonConfig(void)
{
	m_mapCommConfig.clear();
	return LoadCommonConfig();
}

//--------------------------------------------------------
uint32  XmlDataManager::GetCommXMLValue(const String & str)
{
	WGS_XML_READ_LOCK
	std::map<String, uint32>::iterator re = m_mapCommConfig.find(str);
	if(re != m_mapCommConfig.end())
		return m_mapCommConfig[str];
	
	return 0;
}

//////////////////////////StarX///////////////////////////
bool XmlDataManager::LoadSMGameConfig(void)
{
	char strPath[512] = "";
	sprintf(strPath, "../scripts_xml/smallgame_conf.xml");
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/smallgame_conf.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load smallgame_conf.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "game_conf.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/smallgame_conf.xml");
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		String szName = child->Attribute("name");
		uint32 val = StringConverter::parseUnsignedInt(child->Attribute("value"));
		m_mapSMGameConfig.insert(std::make_pair(szName, val));
		child = child->NextSiblingElement();		 
	}
	
	// uint32 test = 0;
	// for(uint32 i = 0; i != 100000; ++ i)
		// if(RandomUInt(100000) > 50000)
			// test ++;
	
	// Log.Error("11", "test[%u]", test);
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReloadSMGameConfig(void)
{
	WGS_XML_WRITE_LOCK
	m_mapSMGameConfig.clear();
	return LoadSMGameConfig();
}

//--------------------------------------------------------
uint32 	XmlDataManager::GetSMXMLValue(const String & str)
{
	WGS_XML_READ_LOCK
	std::map<String, uint32>::iterator re = m_mapSMGameConfig.find(str);
	if(re != m_mapSMGameConfig.end())
		return m_mapSMGameConfig[str];
	
	return 0;
}

//加载任务配置
bool XmlDataManager::LoadMaJonMissionXml(void)
{
	char strPath[512] = "";
	sprintf(strPath, "%s/missions.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/missions.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load missions.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "missions.xml have not root node!");
		return false;
	}
	
	m_majonMissions.clear();
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/missions.xml");
	while(pRoot)
	{
		uint32 type = StringConverter::parseUnsignedInt(pRoot->Attribute("type"));
		String name = pRoot->Attribute("name");
		String sBounty = pRoot->Attribute("bounty");
		String sCoins = pRoot->Attribute("sCoins");
		String sHongbao = pRoot->Attribute("sHongbao");
		TiXmlElement* child = pRoot->FirstChildElement();
		std::vector<MaJonMission> vecMissions;
		while(child != NULL)
		{
			MaJonMission mission;
			mission.model_id = StringConverter::parseUnsignedInt(child->Attribute("fan_id"));
			mission.type = type;
			mission.fan_num = StringConverter::parseUnsignedInt(child->Attribute("fan"));
			mission.coins = StringConverter::parseUnsignedInt(child->Attribute("coins"));
			mission.hongbao = StringConverter::parseUnsignedInt(child->Attribute("hongbao"));
			mission.status = 1;
			mission.sDesc = child->Attribute("desc");	//任务描述
			
			char buf[256] = "";
			if(type != 3)
				sprintf(buf,name.c_str(),child->Attribute("name"));
			else
				sprintf(buf,name.c_str(),child->Attribute("fan"));
			
			mission.sName = buf;
			mission.sBounty += sBounty;
			if(mission.coins)
				mission.sBounty += sCoins;
			
			if(mission.hongbao)
				mission.sBounty += sHongbao;
			
			vecMissions.push_back(mission);
			
			child = child->NextSiblingElement();
		}
		
		m_majonMissions.insert(std::make_pair(type,vecMissions));
		pRoot = pRoot->NextSiblingElement();
	}
	Log.Debug("XmlDataManager", "load ../scripts_xml/missions.xml successfully!");
	return true;
}

bool XmlDataManager::ReLoadMaJonMissionXml(void)
{
	WGS_XML_WRITE_LOCK
	m_majonMissions.clear();
	return LoadMaJonMissionXml();
}

MaJonMission XmlDataManager::CreateMaJonMission(const uint32 mission_type,const uint8 offset_value) 	//创建麻将任务
{
	MaJonMission mission;
	WGS_XML_READ_LOCK
	std::map<uint32,std::vector<MaJonMission> >::iterator re = m_majonMissions.find(mission_type);
	if(re == m_majonMissions.end())
		return mission;
	
	if((re->second).empty())
		return mission;
	
	std::vector<MaJonMission> missions = re->second;
	uint32 missions_size = missions.size();
	// if(mission_type == 1)
		// mission = missions[5];
	// else
	mission = missions[RandomUInt(missions_size - 1)];
	
	uint32 hongbao = 0;
	uint32 coins = 0;
	if(mission.hongbao)
	{
		for(uint8 i=0; i<offset_value; ++i)
		{
			mission.hongbao = uint32(mission.hongbao * 1.2); 
		}
		
		hongbao = mission.hongbao;
	}
	
	if(mission.coins)
	{
		for(uint8 i=0; i<offset_value; ++i)
		{
			mission.coins = uint32(mission.coins * 1.2);
		}
		coins = mission.coins;
	}
	
	char buf[256] = "";
	if(hongbao && coins)
	{
		sprintf(buf,mission.sBounty.c_str(),hongbao ,coins);
	}
	else
	{
		if(hongbao)
		{
			sprintf(buf,mission.sBounty.c_str(),hongbao);
		}
		else if(coins)
		{
			sprintf(buf,mission.sBounty.c_str(),coins);
		}
	}
	
	mission.sBounty = buf;
	
	return mission;
}

bool XmlDataManager::IsConfXmlValueExist(const String & str)
{
	std::map<String, uint32>::iterator re = m_mapGameConfig.find(str);
	if(re != m_mapGameConfig.end())
		return true;
	
	return false;
}

//--------------------------------------------------------
uint32 	XmlDataManager::GetConfXMLValue(const String & str)
{
	WGS_XML_READ_LOCK
	std::map<String, uint32>::iterator re = m_mapGameConfig.find(str);
	if(re != m_mapGameConfig.end())
		return m_mapGameConfig[str];
	
	re = m_mapCommConfig.find(str);
	if(re != m_mapCommConfig.end())
		return m_mapCommConfig[str];
	
	return 0;
}

//-称号---------------------------
bool XmlDataManager::LoadWealthTitle()
{
	char strPath[512] = "";
	sprintf(strPath, "%s/wealthtitle.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/wealthtitle.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadWealthTitle:", "load wealthtitle.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	WealthTitle wt;
	while (NULL != pRoot)
	{
		uint8 typeId = StringConverter::parseUnsignedInt(pRoot->Attribute("id"));
		wt.wealth = StringConverter::parseUnsignedInt(pRoot->Attribute("wealth"));
		wt.desc = pRoot->Attribute("dsc");
		m_mapWealthTitle.insert(std::make_pair(typeId, wt));
		pRoot = pRoot->NextSiblingElement();
	}
	Log.Debug("XmlDataManager::LoadWealthTitle:", "load wealthtitle.xml successfully!");
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReloadWealthTitle()
{
	WGS_XML_WRITE_LOCK
	m_mapWealthTitle.clear();
	return LoadWealthTitle();
}
//--------------------------------------------------------
const uint8 XmlDataManager::GetWealthTitle(const uint32 coin) const
{
	WGS_XML_READ_LOCK
	uint8 typeId = 0;
	std::map<uint8, WealthTitle>::const_iterator iter = m_mapWealthTitle.begin(), iterEnd = m_mapWealthTitle.end();
	if (iter == iterEnd)
	{
		Log.Error("XmlDataManager::GetWealthTitle:", "wealthtitle.xml no data!");
		return 0;
	}
	for (; iter != iterEnd; ++iter)
	{
		if (coin >= iter->second.wealth)
			typeId = iter->first;
		else
			break;
	}
	return typeId;
}
//--------------------------------------------------------
const String * XmlDataManager::GetWealthTitleString(const uint32 & coin)
{
WGS_XML_READ_LOCK
	const String * pszTitle = NULL;
	std::map<uint8, WealthTitle>::const_iterator iter = m_mapWealthTitle.begin(), iterEnd = m_mapWealthTitle.end();
	if (iter == iterEnd)
	{
		Log.Error("XmlDataManager::GetWealthTitleString:", "wealthtitle.xml no data!");
		return NULL;
	}
	for (; iter != iterEnd; ++iter)
	{
		if (coin >= iter->second.wealth)
			pszTitle = &(iter->second.desc);
		else
			break;
	}
	
	return pszTitle;
}
//--------------------------------------------------------
uint32 XmlDataManager::GetWealthTitleIndex(const uint32 &coins)
{
WGS_XML_READ_LOCK
	uint32 index = 0;
	std::map<uint8, WealthTitle>::const_iterator iter = m_mapWealthTitle.begin(), iterEnd = m_mapWealthTitle.end();
	if (iter == iterEnd)
	{
		Log.Error("XmlDataManager::GetWealthTitleString:", "wealthtitle.xml no data!");
		return 0;
	}
	for (; iter != iterEnd; ++iter)
	{
		if (coins >= iter->second.wealth)
			index = iter->first;
		else
			break;
	}
	
	return index;
}
//--------------------------------------------------------
String XmlDataManager::GetWealthTitleByIndex(const uint32 &index)
{
WGS_XML_READ_LOCK
	std::map<uint8, WealthTitle>::iterator iter = m_mapWealthTitle.find(index);
	if (iter != m_mapWealthTitle.end())
		return iter->second.desc;
	return "";
}
//--------------------------------------------------------
bool XmlDataManager::LoadJackerooHortation()
{
	char strPath[512] = "";
	sprintf(strPath, "%s/jackeroohortation.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/jackeroohortation.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadJackerooHortation:", "load jackeroohortation.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("XmlDataManager::LoadJackerooHortation:", "have not node of root!");
		return false;
	}
	// 加载发送礼包条件
	TiXmlElement* pCondition = pRoot->FirstChildElement();
	if (NULL == pCondition)
	{
		Log.Error("XmlDataManager::LoadJackerooHortation:", "have not node of condition!");
		return false;
	}
	m_jackerooHortation.condition = StringConverter::parseUnsignedInt(pCondition->Attribute("value"));
	// 加载礼包
	TiXmlElement* pHortation = pCondition->NextSiblingElement();
	if (NULL == pHortation)
	{
		Log.Error("XmlDataManager::LoadJackerooHortation:", "have not node of hortation!");
		return false;
	}
	TiXmlElement* pGift = pHortation->FirstChildElement();
	while (NULL != pGift)
	{
		m_jackerooHortation.AddGift(StringConverter::parseUnsignedInt(pGift->Attribute("value")));
		pGift = pGift->NextSiblingElement();
	}
	Log.Debug("XmlDataManager::LoadJackerooHortation:", "load jackeroohortation.xml successfully!");
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReloadJackerooHortation()
{
	WGS_XML_WRITE_LOCK
	m_jackerooHortation.Clear();
	return LoadJackerooHortation();
}
//--------------------------------------------------------
bool XmlDataManager::LoadLoginGift()
{
	char strPath[512] = "";
	sprintf(strPath, "%s/logingift.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/logingift.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadLoginGift:", "load logingift.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	m_mapLoginGift.clear();
	LoginGift lg;
	while (NULL != pRoot)
	{
		lg.days = StringConverter::parseUnsignedInt(pRoot->Attribute("days"));
		lg.modelId = StringConverter::parseUnsignedInt(pRoot->Attribute("model_id"));
		lg.number = StringConverter::parseUnsignedInt(pRoot->Attribute("number"));
		m_mapLoginGift.insert(std::make_pair(lg.days, lg));
		pRoot = pRoot->NextSiblingElement();
	}
	Log.Debug("XmlDataManager::LoadLoginGift:", "load logingift.xml successfully!");
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReloadLoginGift()
{
	WGS_XML_WRITE_LOCK
	return LoadLoginGift();
}
//--------------------------------------------------------
bool XmlDataManager::LoadSystemNotices()
{
	char strPath[512] = "";
	sprintf(strPath, "%s/system_notice.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadSystemNotices:", "load system_notice.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	m_lstNotices.clear();
	Notice nt;
	while (NULL != pRoot)
	{
		if (StringConverter::parseUnsignedInt(pRoot->Attribute("status")) > 0)
		{
			nt.msg = pRoot->Attribute("msg");
			nt.interval = StringConverter::parseUnsignedInt(pRoot->Attribute("interval"));
			nt.msgType = StringConverter::parseUnsignedInt(pRoot->Attribute("msgType"));
			nt.gzId = StringConverter::parseUnsignedInt(pRoot->Attribute("gzId"));
			nt.startDate = StringConverter::parseUnsignedInt(pRoot->Attribute("start"));
			nt.finishDate = StringConverter::parseUnsignedInt(pRoot->Attribute("finish"));
			nt.beginTime = StringConverter::parseUnsignedInt(pRoot->Attribute("begin"));
			nt.endTime = StringConverter::parseUnsignedInt(pRoot->Attribute("end"));
			m_lstNotices.push_back(nt);
		}
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadSystemNotices:", "load system_notice.xml successfully!");
	return true;
}

//--------------------------------------------------------
bool XmlDataManager::ReloadSystemNotices()
{
	WGS_XML_WRITE_LOCK
	return LoadSystemNotices();
}

// 加载VIP房间铜钱配置
bool XmlDataManager::LoadViproomNeedcoins()
{
	m_mapVipRoomCoins.clear();
	char strPath[512] = "";
	sprintf(strPath, "%s/viproom_coins.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/viproom_coins.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load viproom_coins.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "viproom_coins.xml have not root node!");
		return false;
	}
	
	while(pRoot)
	{
		uint32 base = StringConverter::parseUnsignedInt(pRoot->Attribute("base"));
		uint32 need_coins = StringConverter::parseUnsignedInt(pRoot->Attribute("need_coins"));
		m_mapVipRoomCoins.insert(std::make_pair(base, need_coins));
		
		pRoot = pRoot->NextSiblingElement();
	}
	Log.Debug("XmlDataManager init", "Start load ../viproom_coins/game_ids.xml successfully");
	return true;
}

bool XmlDataManager::ReLoadViproomNeedcoins()
{
WGS_XML_WRITE_LOCK
	return LoadViproomNeedcoins();
}

// 获取VIP房间铜钱限制
uint32 XmlDataManager::GetVipRoomBaseCoins(const uint32 base_coins)
{
	std::map<uint32, uint32>::iterator mapi = m_mapVipRoomCoins.find(base_coins);
	if(mapi != m_mapVipRoomCoins.end())
		return mapi->second;
	
	return 0;
}

//--------------------------------------------------------
bool XmlDataManager::LoadWebLevelConf(void)
{
	// char strPath[512] = "";
	// sprintf(strPath, "%s/tencent_level_bounty.xml", _GAME_XMLFILE_PATH_);
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/tencent_level_bounty.xml");
	assert(doc.LoadFile());
	
	TiXmlElement* pRoot = doc.RootElement();
	TiXmlElement* child = pRoot->FirstChildElement();
	m_mapWebLvBounty.clear();
	WebLvBounty tl;
	while (NULL != child)
	{
		WebLvBounty tl;
		tl.level = StringConverter::parseUnsignedInt(child->Attribute("lv"));
		tl.money = StringConverter::parseUnsignedInt(child->Attribute("money"));
		tl.match = StringConverter::parseUnsignedInt(child->Attribute("match"));
		tl.change = StringConverter::parseUnsignedInt(child->Attribute("change"));
		tl.jb = StringConverter::parseUnsignedInt(child->Attribute("jb"));
		m_mapWebLvBounty.insert(std::make_pair(tl.level, tl));
		child = child->NextSiblingElement();		
	}
	
	Log.Debug("XmlDataManager::LoadTencentLevelConf:", "load tencent_level_bounty.xml successfully!");
	return true;
}

//--------------------------------------------------------
const WebLvBounty* XmlDataManager::GetWebLevelBounty(const uint32 & level)
{
	WGS_XML_READ_LOCK
	std::map<uint32, WebLvBounty>::iterator re = m_mapWebLvBounty.find(level);
	if(re != m_mapWebLvBounty.end())
		return &m_mapWebLvBounty[level];
	
	return NULL;
}

// 获取游戏分区ID的vector
std::vector<uint32> XmlDataManager::GetGameIDVector()
{
	std::vector<uint32> gameids;
	WGS_XML_READ_LOCK
	
	std::map<String, GZIDInfo>::iterator iter,ei = m_mapGzidInfo.end();
	for(iter = m_mapGzidInfo.begin(); iter!=ei; ++iter)
	{
		gameids.push_back((iter->second).gzId);
	}
	
	return gameids;
}

//--------------------------------------------------------
bool XmlDataManager::LoadChanceConf(void)
{	
	// char strPath[512] = "";
	// sprintf(strPath, "%s/chance.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc("../scripts_xml/chance.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadChanceConf:", "load chance.xml failed!");
		return false;
	}
	m_listChances.clear();
	uint32 id = 0;
	TiXmlElement* pRoot = doc.RootElement();
	while(pRoot != NULL)
	{
		ChanceList lst;
		lst.kind_id = StringConverter::parseUnsignedInt(pRoot->Attribute("first"));
		TiXmlElement* child = pRoot->FirstChildElement();		
		while(child != NULL)
		{
			ChanceItem rt;
			rt.id = ++id;
			rt.chance = StringConverter::parseUnsignedInt(child->Attribute("second"));
			rt.type = StringConverter::parseUnsignedInt(child->Attribute("type"));
			rt.model_id = StringConverter::parseUnsignedInt(child->Attribute("model_id"));
			rt.num = StringConverter::parseUnsignedInt(child->Attribute("num"));
			rt.num2 = StringConverter::parseUnsignedInt(child->Attribute("num2"));
			rt.max_emerge = StringConverter::parseUnsignedInt(child->Attribute("emerge"));			
			rt.desc = child->Attribute("desc");
			lst.items.push_back(rt);
			
			child = child->NextSiblingElement();	
		}
		
		m_listChances.push_back(lst);
		pRoot = pRoot->NextSiblingElement();	
	}
	return true;
}

//--------------------------------------------------------
bool XmlDataManager::ReloadChanceConf(void)
{
	WGS_XML_WRITE_LOCK
	LoadChanceConf();
	return true;
}

//--------------------------------------------------------
const ChanceItem * XmlDataManager::GetChanceItem(void)
{
	WGS_XML_READ_LOCK
	uint32 first = 0;
	uint32 rand = RandomUInt(1, GetSMXMLValue("ROULETTE_CHANCE")-1);	
	std::list<ChanceList>::iterator ci, endci = m_listChances.end();
	for(ci = m_listChances.begin(); ci != endci; ++ ci)
	{
		if((*ci).kind_id == 0)
			continue;
			
		first += (*ci).kind_id;
		if(rand <= first)
		{
			uint32 second = 0;
			uint32 rand1 = RandomUInt(1, GetSMXMLValue("ROULETTE_CHANCE")-1);
			std::list<ChanceItem>::iterator ii, endii = (*ci).items.end();
			for(ii = (*ci).items.begin(); ii != endii; ++ii)
			{
				if((*ii).chance == 0)
					continue;
					
				second += (*ii).chance;
				if(rand1 <= second)
				{
					return &(*ii);
				}
			}
		}
	}
	
	return NULL;
}

//--------------------------------------------------------
const ChanceItem *XmlDataManager::GetChanceItem(const uint32 & kind_id)
{
	WGS_XML_READ_LOCK
	std::list<ChanceList>::iterator iter, enditer = m_listChances.end();
	for (iter = m_listChances.begin(); iter != enditer; ++ iter)
	{
		if ((*iter).kind_id != kind_id)
			continue;
		uint32 first = 0;
		uint32 rand = RandomUInt(1, 100000);
		std::list<ChanceItem>::iterator it, endit = (*iter).items.end();
		for (it = (*iter).items.begin(); it != endit; ++ it)
		{			
			first += (*it).chance;
			if (rand <= first)
			{
				if ((*it).max_emerge != 0)
				{
					(*it).curr_emerge ++;
					if ((*it).curr_emerge >= (*it).max_emerge)
					{// 超出最大产生限制
						return NULL;
					}
				}
				return &(*it);
			}
			
		}		
	}
	
	return NULL;
}

uint32 XmlDataManager::GetChanceList(const uint32 &kind_id, std::list<ChanceItem> & lstChance)
{
	WGS_XML_READ_LOCK
	std::list<ChanceList>::iterator iter, enditer = m_listChances.end();
	for (iter = m_listChances.begin(); iter != enditer; ++ iter)
	{
		if ((*iter).kind_id == kind_id)
		{
			lstChance = (*iter).items;
			return lstChance.size();
		}
	}
	return 0;
}

//--------------------------------------------------------
bool XmlDataManager::LoadGZIDName()
{
	// char strPath[512] = "";
	// sprintf(strPath, "../scripts_xml/%s/gz_id.xml", _GAME_XMLFILE_PATH_);
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/gz_id.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadGZIDName", "load gz_id.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("XmlDataManager::LoadGZIDName", "gz_id.xml have not root node!");
		return false;
	}
	while(pRoot)
	{
		m_mapGZIDName.insert(std::make_pair(StringConverter::parseUnsignedInt(pRoot->Attribute("id")), pRoot->Attribute("name")));
		pRoot = pRoot->NextSiblingElement();
	}
	Log.Debug("XmlDataManager::LoadGZIDName:", "load gz_id.xml successfully!");
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReloadGZIDName()
{
	WGS_XML_WRITE_LOCK
	m_mapGZIDName.clear();
	LoadGZIDName();
	return true;
}
//--------------------------------------------------------
String XmlDataManager::GetGzIdName(const uint32 id)
{
	WGS_XML_READ_LOCK
	std::map<uint32, String>::iterator iter = m_mapGZIDName.find(id);
	if (iter != m_mapGZIDName.end())
		return iter->second;
	return String("");
}

//--------------------------------------------------------
const LoginGift* XmlDataManager::GetLoginGift(const uint32 & day)
{
	WGS_XML_READ_LOCK
	uint32 temp = day;
	if (temp > m_mapLoginGift.size())
		temp = m_mapLoginGift.size();
		
	std::map<uint32, LoginGift>::iterator it = m_mapLoginGift.find(temp);
	if(it == m_mapLoginGift.end())
		return NULL;
	
	return &it->second;
}

//--------------------------------------------------------
bool XmlDataManager::LoadServerIP(void)
{
	TiXmlDocument doc("../scripts_xml/server_ip.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::SERVER_IP:", "load server_ip.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	m_lstServerIP.clear();
	while (NULL != pRoot)
	{
		ServerIP ip;
		ip.id = StringConverter::parseUnsignedInt(pRoot->Attribute("gameid"));
		ip.ip = pRoot->Attribute("ip");
		ip.port = StringConverter::parseUnsignedInt(pRoot->Attribute("port"));
		m_lstServerIP.push_back(ip);
		pRoot = pRoot->NextSiblingElement();		
	}
	
	return true;
}

//--------------------------------------------------------
bool XmlDataManager::ReloadServerIP(void)
{
	WGS_XML_WRITE_LOCK
	m_lstServerIP.clear();	
	return LoadServerIP();
}

//--------------------------------------------------------
const ServerIP* XmlDataManager::GetServerIP(const uint32 & gameid)
{
	WGS_XML_READ_LOCK
	std::list<ServerIP>::iterator it, endit = m_lstServerIP.end();
	for(it = m_lstServerIP.begin(); it != endit; ++ it)
	{
		if((*it).id == gameid)
		{
			return &(*it);
		}
	}
	
	return NULL;
}

//--------------------------------------------------------
bool XmlDataManager::LoadMailModel(void)
{
	TiXmlDocument doc("../scripts_xml/mailmodel.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager", "load mailmodel.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	m_mapMailModel.clear();
	while (NULL != pRoot)
	{
		MailModel mail;
		String szKey = pRoot->Attribute("name");
		mail.szTitle = pRoot->Attribute("title");
		mail.szContent = pRoot->Attribute("content");
		m_mapMailModel.insert(std::make_pair(szKey, mail));
		pRoot = pRoot->NextSiblingElement();		
	}
	
	return true;
}

//--------------------------------------------------------
bool XmlDataManager::ReloadMailModel(void)
{
	WGS_XML_WRITE_LOCK
	return LoadMailModel();
}

//--------------------------------------------------------
const MailModel * XmlDataManager::GetMailModel(const String & szKey)
{
	WGS_XML_READ_LOCK
	std::map<String, MailModel>::iterator mapit = m_mapMailModel.find(szKey);
	if(mapit == m_mapMailModel.end())
		return NULL;
	
	return &mapit->second;
}

//--------------------------------------------------------
bool XmlDataManager::LoadGameIDXml()
{
	char strPath[512] = "";
	sprintf(strPath, "%s/game_ids.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load game_ids.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "game_ids.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/game_ids.xml");
	m_mapGzidInfo.clear();
	
	while(pRoot)
	{
		GZIDInfo gz;
		String pName = pRoot->Attribute("name");
		gz.gzId = StringConverter::parseUnsignedInt(pRoot->Attribute("val"));
		gz.minVersion = pRoot->Attribute("v_min");
		gz.maxVersion = pRoot->Attribute("v_max");
		gz.maxAddr = pRoot->Attribute("v_addr");
		gz.maxSize = StringConverter::parseUnsignedInt(pRoot->Attribute("v_size"));
		m_mapGzidInfo.insert(std::make_pair(pName, gz));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/game_ids.xml successfully");
	return true;
}

//--------------------------------------------------------
bool XmlDataManager::ReLoadGameIDXml()
{
WGS_XML_WRITE_LOCK
	LoadGameIDXml();
	return true;
}

// const GZIDInfo *XmlDataManager::GetGZIDInfo(const uint32 & gz_id)
// {
	// std::map<uint32, GZIDInfo>::iterator iter = m_mapGzidInfo.find(gz_id);
	// if (iter != m_mapGzidInfo.end())
	// {
		// return &iter->second;
	// }
	// return NULL;
// }
//--------------------------------------------------------
bool XmlDataManager::LoadBuyLargessXml()
{
	TiXmlDocument doc("../scripts_xml/buy_largess.xml");	
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load buy_largess.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "buy_largess.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/buy_largess.xml");
	m_lstBuyLargess.clear();
	
	while(pRoot)
	{
		BuyLargess buy;
		buy.buy = StringConverter::parseUnsignedInt(pRoot->Attribute("buy"));
		buy.largess = StringConverter::parseUnsignedInt(pRoot->Attribute("largess"));
		buy.number = StringConverter::parseUnsignedInt(pRoot->Attribute("number"));
		buy.exp = StringConverter::parseUnsignedInt(pRoot->Attribute("exp"));
		m_lstBuyLargess.push_back(buy);
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/buy_largess.xml successfully");
	return true;
}
//--------------------------------------------------------
const BuyLargess *XmlDataManager::GetBuyLargess(const uint32 & buy_id)
{
	std::list<BuyLargess>::iterator iter, enditer = m_lstBuyLargess.end();
	for (iter = m_lstBuyLargess.begin(); iter != enditer; ++ iter)
	{
		if ((*iter).buy == buy_id)
			return &(*iter);
	}
	return NULL;
}

// 加载赠送打折卡配置
bool XmlDataManager::LoadGiveLeCardsXml()
{
	TiXmlDocument doc("../scripts_xml/reg_give_lecards.xml");	
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load reg_give_lecards.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "reg_give_lecards.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/reg_give_lecards.xml");
	m_lstLeCardsGive.clear();
	
	while(pRoot)
	{
		LeCardGive lc;
		lc.days = StringConverter::parseUnsignedInt(pRoot->Attribute("days"));
		lc.num = StringConverter::parseUnsignedInt(pRoot->Attribute("num"));
		lc.type = StringConverter::parseUnsignedInt(pRoot->Attribute("type"));
		
		m_lstLeCardsGive.push_back(lc);
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/reg_give_lecards.xml successfully");
	return true;
}
//--------------------------------------------------------
bool XmlDataManager::ReLoadGiveLeCardsXml()
{
WGS_XML_WRITE_LOCK
	LoadGiveLeCardsXml();
	return true;
}
//--------------------------------------------------------
std::vector<LeCardGive> XmlDataManager::getGiveLeCardsInfo(const uint32 & reg_days)
{
	std::vector<LeCardGive> leCards;
	std::list<LeCardGive>::iterator iter,ei = m_lstLeCardsGive.end();
	for(iter = m_lstLeCardsGive.begin(); iter!=ei; ++iter)
	{
		if(reg_days >= (*iter).days)
		{
			leCards.push_back(*iter);
		}
	}
	
	return leCards;
}
	
// 加载水果机配置
void XmlDataManager::LoadFruitXml(void)
{
	TiXmlDocument doc("../scripts_xml/subgame/fruit.xml");
	if(!doc.LoadFile())
	{
		Log.Error("Fruit Test", "load fruit.xml failed!");
		return;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("Fruit Test", "fruit.xml have not root node!");
		return;
	}
	
	m_vFruitsBounty.clear();
	
	uint32 chance_id = 0;
	while(pRoot != NULL)
	{
		FruitBounty fb;
		fb.chance_id = ++chance_id;
		fb.chance = StringConverter::parseUnsignedInt(pRoot->Attribute("chance"));
		fb.bounty_id = StringConverter::parseUnsignedInt(pRoot->Attribute("bounty_id"));
		fb.big = StringConverter::parseUnsignedInt(pRoot->Attribute("big"));
		fb.multiple = StringConverter::parseUnsignedInt(pRoot->Attribute("multiple"));
		fb.exist = StringConverter::parseUnsignedInt(pRoot->Attribute("exist"));
		
		m_vFruitsBounty.push_back(fb);
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Notice("Fruit::LoadFruitXml","load subgames/Fruit.xml successfully!");
}
//--------------------------------------------------------
void XmlDataManager::ReLoadFruitXml(void)
{
WGS_XML_WRITE_LOCK
	m_vFruitsBounty.clear();
	LoadFruitXml();
}

//得到水果机中奖项
FruitBounty XmlDataManager::GetFruitBounty(void)
{
	FruitBounty fb;
	
	uint32 rand = RandomUInt(100000);
	uint32 chance = 0;
	std::list<FruitBounty>::iterator ri, endri = m_vFruitsBounty.end();
	for(ri = m_vFruitsBounty.begin(); ri != endri; ++ ri)
	{
		chance += (*ri).chance;
		if(rand <= chance)
		{
			return *ri;
		}
	}
	return fb;
}
//--------------------------------------------------------
bool XmlDataManager::LoadItemSetConfig()
{
	WGS_XML_WRITE_LOCK
	m_mapItemSetNode.clear();
	char strPath[512] = "";
	sprintf(strPath, "%s/item_set.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	if(!doc.LoadFile())
	{
		Log.Error("LoadItemSetConfig", "load item_set.xml failed!");
		return false;
	}
	TiXmlElement* pNode = doc.RootElement();
	if (NULL == pNode)
	{
		Log.Error("LoadItemSetConfig", "item_set.xml have not nodes!");
		return false;
	}
	while (pNode != NULL)
	{
		m_mapItemSetNode.insert(std::make_pair(pNode->Value(), *pNode));
		pNode = pNode->NextSiblingElement();
	}
	Log.Success("XmlDataManager::LoadItemSetConfig()", "Load %s success, size = %u", strPath, m_mapItemSetNode.size());
	return true;
}
//--------------------------------------------------------
TiXmlElement * XmlDataManager::GetItemSetNode(const String &key)
{
	std::map<String, TiXmlElement>::iterator iter = m_mapItemSetNode.find(key);
	if (iter == m_mapItemSetNode.end())
		return NULL;
	return &iter->second;
}
//--------------------------------------------------------
bool XmlDataManager::GetItemSet(const uint32 index, ItemSet &iset)
{
	WGS_XML_WRITE_LOCK
	String key = "itemset_";
	key += StringConverter::toString(index);
	TiXmlElement *pNode = GetItemSetNode(key);
	if (pNode)
	{
		iset.base = StringConverter::parseUnsignedInt(pNode->Attribute("base"));
		TiXmlElement* pChild = pNode->FirstChildElement();
		while (pChild)
		{
			// 从列表中获取奖品
			ItemData iData;
			iData.odds = StringConverter::parseUnsignedInt(pChild->Attribute("odds"));
			if (strcmp(pChild->Value(), "list") == 0)
			{
				if (GetDataFromList(StringConverter::parseUnsignedInt(pChild->Attribute("script")), iData))
				{
					iset.vecItem.push_back(iData);
				}
			}
			else if (strcmp(pChild->Value(), "item") == 0)
			{
				iData.modelId = StringConverter::parseUnsignedInt(pChild->Attribute("model"));
				iData.num = RandomUInt(StringConverter::parseUnsignedInt(pChild->Attribute("min_num")), StringConverter::parseUnsignedInt(pChild->Attribute("max_num")));
				iset.vecItem.push_back(iData);
			}
			pChild = pChild->NextSiblingElement();
		}
		return true;
	}
	return false;
}
//--------------------------------------------------------
bool XmlDataManager::GetDataFromList(const uint32 index, ItemData &idata)
{
	String key = "list_";
	key += StringConverter::toString(index);
	TiXmlElement *pNode = GetItemSetNode(key);
	if (pNode)
	{
		uint32 base = StringConverter::parseUnsignedInt(pNode->Attribute("base"));
		std::vector<TiXmlElement *> vecNode;
		TiXmlElement *pChild = pNode->FirstChildElement();
		while (pChild)
		{
			vecNode.push_back(pChild);
			pChild = pChild->NextSiblingElement();
		}
		uint32 rd = 0;
		if (base > 0)
		{
			rd = RandomUInt(base-1);
			uint32 count = 0;
			std::vector<TiXmlElement *>::iterator iter = vecNode.begin();
			pChild = *iter;
			for (; iter != vecNode.end(); ++iter)
			{
				uint32 odds = StringConverter::parseUnsignedInt((*iter)->Attribute("odds"));
				count += odds;
				if (rd < count)
				{
					pChild = (*iter);
					break;
				}
			}
		}
		else
		{
			rd = RandomUInt(vecNode.size()-1);
			pChild = vecNode[rd];
		}
		if (pChild)
		{
			if (strcmp(pChild->Value(), "list") == 0)
			{
				return GetDataFromList(StringConverter::parseUnsignedInt(pChild->Attribute("script")), idata);
			}
			else if (strcmp(pChild->Value(), "item") == 0)
			{
				idata.modelId = StringConverter::parseUnsignedInt(pChild->Attribute("model"));
				idata.num = RandomUInt(StringConverter::parseUnsignedInt(pChild->Attribute("min_num")), StringConverter::parseUnsignedInt(pChild->Attribute("max_num")));
				return true;
			}
		}
	}
	return false;
}
//--------------------------------------------------------
void XmlDataManager::LoadHappyFarm(void)
{
	TiXmlDocument doc("../scripts_xml/happy_farm.xml");
	if(!doc.LoadFile())
	{
		Log.Error("happy_farm Test", "load happy_farm.xml failed!");
		return;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("happy_farm Test", "happy_farm.xml have not root node!");
		return;
	}	
	m_mapHappyFarms.clear();	
	while(pRoot != NULL)
	{
		HappyFarm hf;
		hf.model_id = StringConverter::parseUnsignedInt(pRoot->Attribute("id"));
		hf.price = StringConverter::parseUnsignedInt(pRoot->Attribute("price"));
		hf.feeding_cycle = StringConverter::parseUnsignedInt(pRoot->Attribute("feeding_cycle"));
		hf.earnings = StringConverter::parseUnsignedInt(pRoot->Attribute("earnings"));
		hf.need_vip = StringConverter::parseUnsignedInt(pRoot->Attribute("need_vip"));
		hf.szName = pRoot->Attribute("desc");
		m_mapHappyFarms.insert(std::make_pair(hf.model_id, hf));
		pRoot = pRoot->NextSiblingElement();
	}	
	Log.Notice("happy_farm::LoadFruitXml","load happy_farm.xml successfully!");
}
//--------------------------------------------------------
const HappyFarm* XmlDataManager::GetHappyFarm(const uint32 &id)
{
	std::map<uint32, HappyFarm>::iterator mapi = m_mapHappyFarms.find(id);
	if (mapi != m_mapHappyFarms.end())
		return &mapi->second;
	return NULL;
}
//--------------------------------------------------------
uint32 XmlDataManager::GetHappyFarmList(std::map<uint32, HappyFarm> &mapHappyFarm)
{
	mapHappyFarm.clear();
	mapHappyFarm = m_mapHappyFarms;
	return mapHappyFarm.size();
}

// 加载通用排行配置
bool XmlDataManager::LoadCommonOrderXml(void)
{
	char strPath[512] = "";
	sprintf(strPath, "%s/common_order.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load common_order.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "common_order.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager", "Start load %s", strPath);
	
	m_mapCommonOrder.clear();
	
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		stOrderInfo oi;
		oi.strKey = child->Attribute("name");
		oi.order_type = StringConverter::parseUnsignedInt(child->Attribute("order_index"));
		oi.orderValu_key = child->Attribute("value_key");
		oi.orderValu_key2 = child->Attribute("value_key2");
		oi.maxPlayerNum = StringConverter::parseUnsignedInt(child->Attribute("max_num"));
		
		if(child->HasAttribute("reset_mode"))
			oi.reset_mode = StringConverter::parseUnsignedInt(child->Attribute("reset_mode"));
		
		if(child->HasAttribute("reset_data"))
			oi.reset_data = StringConverter::parseUnsignedInt(child->Attribute("reset_data"));
		
		if(child->HasAttribute("update_mode"))
			oi.update_mode = StringConverter::parseUnsignedInt(child->Attribute("update_mode"));
	
		if(child->HasAttribute("update_data"))
			oi.update_data = StringConverter::parseUnsignedInt(child->Attribute("update_data"));
		
		if(child->HasAttribute("data_gzid"))
			oi.data_gzid = StringConverter::parseUnsignedInt(child->Attribute("data_gzid"));
		
		if(child->HasAttribute("last_resetTimer"))
			oi.last_resetTimer = StringConverter::parseUnsignedInt(child->Attribute("last_resetTimer"));
		
		String strGzid = "";
		if(child->HasAttribute("gz_id"))
		{
			strGzid = child->Attribute("gz_id");
			std::vector<String> vStrGzid = StringUtil::split(strGzid, ",");
			
			std::vector<String>::iterator itStr, eiStr = vStrGzid.end();
			for(itStr = vStrGzid.begin(); itStr!=eiStr; ++itStr)
			{
				oi.vGzids.push_back(StringConverter::parseUnsignedInt(*itStr));
			}
		}
		
		String strAgent = "";
		if(child->HasAttribute("agent_id"))
		{
			strAgent = child->Attribute("agent_id");
			std::vector<String> vStrAgent = StringUtil::split(strAgent, ",");
			
			std::vector<String>::iterator itStr, eiStr = vStrAgent.end();
			for(itStr = vStrAgent.begin(); itStr!=eiStr; ++itStr)
			{
				oi.vAgents.push_back(StringConverter::parseUnsignedInt(*itStr));
			}
		}
		
		m_mapCommonOrder.insert(std::make_pair(oi.order_type, oi));
		child = child->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager", "load %s sucess order size[%u]!", strPath,m_mapCommonOrder.size());
	return true;
}

bool XmlDataManager::ReLoadCommonOrderXml(void)
{
WGS_XML_WRITE_LOCK
	return LoadCommonOrderXml();
}

// 获得通用排行配置
std::map<uint32,stOrderInfo> XmlDataManager::GetCommonOrderMap(void)
{
WGS_XML_WRITE_LOCK
	return m_mapCommonOrder;
}

stOrderInfo XmlDataManager::GetOrderValueKey(const uint32 & order_type)
{
	stOrderInfo temp;
WGS_XML_WRITE_LOCK
	std::map<uint32, stOrderInfo>::iterator fit = m_mapCommonOrder.find(order_type);
	if(fit != m_mapCommonOrder.end())
		return fit->second;
	
	return temp;
}

// 修改排行重置时间
void XmlDataManager::SetCommonOrderResetTimer(const uint32 & order_id, const uint32 & timer)
{
WGS_XML_WRITE_LOCK
	char strPath[512] = "";
	sprintf(strPath, "%s/common_order.xml", _GAME_XMLFILE_PATH_);
	
	TiXmlDocument doc(strPath);
	if(!doc.LoadFile())
		return;
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
		return;
	
	m_mapCommonOrder.clear();
	
	bool bChange = false;
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		stOrderInfo oi;
		oi.strKey = child->Attribute("name");
		oi.order_type = StringConverter::parseUnsignedInt(child->Attribute("order_index"));
		oi.orderValu_key = child->Attribute("value_key");
		oi.orderValu_key2 = child->Attribute("value_key2");
		oi.maxPlayerNum = StringConverter::parseUnsignedInt(child->Attribute("max_num"));
		
		if(child->HasAttribute("reset_mode"))
			oi.reset_mode = StringConverter::parseUnsignedInt(child->Attribute("reset_mode"));
		
		if(child->HasAttribute("reset_data"))
			oi.reset_data = StringConverter::parseUnsignedInt(child->Attribute("reset_data"));
		
		if(child->HasAttribute("update_mode"))
			oi.update_mode = StringConverter::parseUnsignedInt(child->Attribute("update_mode"));
	
		if(child->HasAttribute("update_data"))
			oi.update_data = StringConverter::parseUnsignedInt(child->Attribute("update_data"));
		
		if(child->HasAttribute("data_gzid"))
			oi.data_gzid = StringConverter::parseUnsignedInt(child->Attribute("data_gzid"));
		
		if(child->HasAttribute("last_resetTimer"))
		{
			if(oi.order_type == order_id)
			{
				child->SetAttribute("last_resetTimer", StringConverter::toString(timer).c_str());
				bChange = true;
			}
			
			oi.last_resetTimer = StringConverter::parseUnsignedInt(child->Attribute("last_resetTimer"));
		}
		
		String strGzid = "";
		if(child->HasAttribute("gz_id"))
		{
			strGzid = child->Attribute("gz_id");
			std::vector<String> vStrGzid = StringUtil::split(strGzid, ",");
			
			std::vector<String>::iterator itStr, eiStr = vStrGzid.end();
			for(itStr = vStrGzid.begin(); itStr!=eiStr; ++itStr)
			{
				oi.vGzids.push_back(StringConverter::parseUnsignedInt(*itStr));
			}
		}
		
		String strAgent = "";
		if(child->HasAttribute("agent_id"))
		{
			strAgent = child->Attribute("agent_id");
			std::vector<String> vStrAgent = StringUtil::split(strAgent, ",");
			
			std::vector<String>::iterator itStr, eiStr = vStrAgent.end();
			for(itStr = vStrAgent.begin(); itStr!=eiStr; ++itStr)
			{
				oi.vAgents.push_back(StringConverter::parseUnsignedInt(*itStr));
			}
		}
		
		m_mapCommonOrder.insert(std::make_pair(oi.order_type, oi));
		child = child->NextSiblingElement();
	}
	
	
	if(bChange)
		doc.SaveFile();
}

bool XmlDataManager::LoadGameNameXml(void)
{
WGS_XML_WRITE_LOCK
	TiXmlDocument doc("../scripts_xml/game_name.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load game_name.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "game_name.xml have not root node!");
		return false;
	}
	
	m_vGameIDNames.clear();
	m_mapGzIDNames.clear();
	
	while(pRoot)
	{
		uint32 type = StringConverter::parseUnsignedInt(pRoot->Attribute("type"));
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			if(type == 1)
			{
				stGameModelName stGMN;
				stGMN.game_id = StringConverter::parseUnsignedInt(child->Attribute("game_id"));
				stGMN.model_id = StringConverter::parseUnsignedInt(child->Attribute("model_id"));
				stGMN.name = child->Attribute("name");
				
				m_vGameIDNames.push_back(stGMN);
			}
			else
			{
				uint32 gz_id = StringConverter::parseUnsignedInt(child->Attribute("gz_id"));
				String strName = child->Attribute("name");
				
				m_mapGzIDNames.insert(std::make_pair(gz_id, strName));
			}
			
			child = child->NextSiblingElement();
		}
		
		pRoot = pRoot->NextSiblingElement();
	}
	
	return true;
}

bool XmlDataManager::ReLoadGameNameXml(void)
{
	return LoadGameNameXml();
}

String XmlDataManager::GetGameNameByGameModelID(const uint32 & game_id, const uint32 & model_id)
{
WGS_XML_WRITE_LOCK
	std::vector<stGameModelName>::iterator iter, ei = m_vGameIDNames.end();
	for(iter = m_vGameIDNames.begin(); iter!=ei; ++iter)
	{
		if((*iter).game_id == game_id && (*iter).model_id == model_id)
		{
			return (*iter).name;
		}
	}
	
	return "";
}

String XmlDataManager::GetGameNameByGzID(const uint32 & gz_id)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, String>::iterator fit = m_mapGzIDNames.find(gz_id);
	if(fit == m_mapGzIDNames.end())
		return "";
	
	return fit->second;
}

bool XmlDataManager::LoadCenterBattleOpenCoinsXml(void)
{
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/centerbattle_opencoins.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load centerbattle_opencoins.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "centerbattle_opencoins.xml have not root node!");
		return false;
	}
	
	m_mapCenterBattleOpenCoins.clear();
	
	while(pRoot)
	{
		// 运营商ID层
		std::map<uint32, std::vector<stCenterBattleOpenCoins> > mapBattleOpenCoins;
		uint32 agent_id = StringConverter::parseUnsignedInt(pRoot->Attribute("agent_id"));
		// Log.Debug("LoadCenterBattleOpenCoinsXml","m_agent_id[%u] ", m_agent_id);
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{// 游戏ID层
				uint32 game_id = StringConverter::parseUnsignedInt(child->Attribute("game_id"));
				std::vector<stCenterBattleOpenCoins> vCBOC;
				// Log.Debug("LoadCenterBattleOpenCoinsXml","	game_id[%u] ", game_id);
				
				TiXmlElement* child2 = child->FirstChildElement();
				while(child2)
				{
					stCenterBattleOpenCoins stCBO;
					stCBO.model_id = StringConverter::parseUnsignedInt(child2->Attribute("model_id"));
					stCBO.num = StringConverter::parseUnsignedInt(child2->Attribute("num"));
					stCBO.loop = StringConverter::parseUnsignedInt(child2->Attribute("loop"));
					stCBO.mode = StringConverter::parseUnsignedInt(child2->Attribute("mode"));
					stCBO.time = StringConverter::parseUnsignedInt(child2->Attribute("time"));
					stCBO.min = StringConverter::parseUnsignedInt(child2->Attribute("min"));
					
					stCBO.desc = child2->Attribute("desc");
					
					if(child2->HasAttribute("watch"))
					{// 观战模式
						stCBO.watch = StringConverter::parseUnsignedInt(child2->Attribute("watch"));
					}
					
					if(child2->HasAttribute("free_mode"))
					{// 免费模式（1 时间段 2 周期）
						stCBO.free_mode = StringConverter::parseUnsignedInt(child2->Attribute("free_mode"));
					}
					
					if(child2->HasAttribute("free_begin_time"))
					{// 免费开始时间
						stCBO.free_begin_time = StringConverter::parseUnsignedInt(child2->Attribute("free_begin_time"));
					}
					
					if(child2->HasAttribute("free_end_time"))
					{// 免费结束时间
						stCBO.free_end_time = StringConverter::parseUnsignedInt(child2->Attribute("free_end_time"));
					}
					
					if(child2->HasAttribute("aa_num"))
					{// AA制付费数量
						stCBO.aa_num = StringConverter::parseUnsignedInt(child2->Attribute("aa_num"));
					}
					
					if(child2->HasAttribute("pf"))
					{// 玩法支持的平台.
						String strPf = child2->Attribute("pf");
						stCBO.vPfs = StringUtil::split(strPf, ",");
					}
					
					if(child2->HasAttribute("force_time"))
					{// 强制开始时间
						stCBO.force_time = StringConverter::parseUnsignedInt(child2->Attribute("force_time"));
					}
					
					if(child2->HasAttribute("dj_per"))
					{// 强制开始时间
						stCBO.fDjPercent = float(StringConverter::parseUnsignedInt(child2->Attribute("dj_per")) / 100.0f);
						// Log.Debug("LoadCenterBattleOpenCoinsXml","		model_id[%u] loop[%u] mode[%u] per[%f]", stCBO.model_id, stCBO.loop, stCBO.mode, stCBO.fDjPercent);
					}
					
					if(child2->HasAttribute("close_ownerrecord"))
					{// 强制开始时间
						stCBO.nCloseOwnerRecord = StringConverter::parseUnsignedInt(child2->Attribute("close_ownerrecord"));
					}
					
					if(child2->HasAttribute("check_sameip"))
					{// 检测同IP玩家是否可以进入同一组局牌桌
						stCBO.bCheckSameIp = StringConverter::parseUnsignedInt(child2->Attribute("check_sameip"));
					}
					
					if(child2->HasAttribute("gamestart_join"))
					{// 游戏开始后是否可以加入牌桌
						stCBO.gamestart_join = StringConverter::parseUnsignedInt(child2->Attribute("gamestart_join"));
					}
					
					if(child2->HasAttribute("unready_kick_count"))
					{// 未准备次数超限踢出房间
						stCBO.unready_kick_count = StringConverter::parseUnsignedInt(child2->Attribute("unready_kick_count"));
					}
					
					if(child2->HasAttribute("idel_kick_timer"))
					{// 空闲未准备踢出超限时间
						stCBO.idel_kick_timer = StringConverter::parseUnsignedInt(child2->Attribute("idel_kick_timer"));
					}
					
					if(child2->HasAttribute("tuoguan_kick_count"))
					{// 托管次数超限被踢
						stCBO.tuoguan_kick_count = StringConverter::parseUnsignedInt(child2->Attribute("tuoguan_kick_count"));
					}
					
					if(child2->HasAttribute("use_club_diamand"))
					{// 是否使用俱乐部钻石
						stCBO.use_club_diamand = StringConverter::parseUnsignedInt(child2->Attribute("use_club_diamand"));
					}
					
					if(child2->HasAttribute("join_point_lsestMult"))
					{// 金币场，加入最低不能低于底分的倍数
						stCBO.join_point_lsestMult = StringConverter::parseUnsignedInt(child2->Attribute("join_point_lsestMult"));
					}
					
					if(child2->HasAttribute("exit_point_lsestMult"))
					{// 金币场，离开最低不能低于底分的倍数
						stCBO.exit_point_lsestMult = StringConverter::parseUnsignedInt(child2->Attribute("exit_point_lsestMult"));
					}
					
					vCBOC.push_back(stCBO);
					child2 = child2->NextSiblingElement();
				}
				
				mapBattleOpenCoins.insert(std::make_pair(game_id, vCBOC));
				child = child->NextSiblingElement();
		}
		
		m_mapCenterBattleOpenCoins.insert(std::make_pair(agent_id, mapBattleOpenCoins));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("LoadCenterBattleOpenCoinsXml","Load centerbattle_opencoins.xml size[%u] sucess!", m_mapCenterBattleOpenCoins.size());
	return true;
}

bool XmlDataManager::ReLoadCenterBattleOpenCoinsXml(void)
{
WGS_XML_WRITE_LOCK
	return LoadCenterBattleOpenCoinsXml();
}

stCenterBattleOpenCoins XmlDataManager::GetCenterBattleOpenCoins(const uint32 & agent_id, const uint32 & game_id, const uint32 & value, const uint8 & type, const uint8 & mode)
{// 开局费用，先默认返回1
	stCenterBattleOpenCoins stCBOC;
	if(!type)
		return stCBOC;
	
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, std::vector<stCenterBattleOpenCoins> > >::iterator fit = m_mapCenterBattleOpenCoins.find(agent_id);
	if(fit == m_mapCenterBattleOpenCoins.end())
		fit = m_mapCenterBattleOpenCoins.find(0);
	
	if(fit == m_mapCenterBattleOpenCoins.end())
		return stCBOC;
	
	std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator fit2 = fit->second.find(game_id);
	if(fit2 == fit->second.end())
		return stCBOC;
	
	std::vector<stCenterBattleOpenCoins>::iterator iter,ei = fit2->second.end();
	for(iter = fit2->second.begin(); iter!=ei; ++iter)
	{
		if(type == enCenterBattleLimitType_Loop)
		{// 轮数限制
			if((*iter).loop == value && (*iter).mode == mode)
				return *iter;
		}
		else
		{// 时间限制
			if((*iter).time == value && (*iter).mode == mode)
				return *iter;
		}
	}
	
	return stCBOC;
}

stCenterBattleOpenCoins XmlDataManager::GetCenterBattleOpenCoins(const uint32 & agent_id, 
												const uint32 & game_id, 
												const uint32 & item_model, 
												const uint32 & item_num, 
												const uint32 & loop, 
												const uint8 & mode)
{
	stCenterBattleOpenCoins stCBOC;
	
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, std::vector<stCenterBattleOpenCoins> > >::iterator fit = m_mapCenterBattleOpenCoins.find(agent_id);
	if(fit == m_mapCenterBattleOpenCoins.end())
		fit = m_mapCenterBattleOpenCoins.find(0);
	
	if(fit == m_mapCenterBattleOpenCoins.end())
		return stCBOC;
	
	std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator fit2 = fit->second.find(game_id);
	if(fit2 == fit->second.end())
		return stCBOC;
	
	std::vector<stCenterBattleOpenCoins>::iterator iter,ei = fit2->second.end();
	for(iter = fit2->second.begin(); iter!=ei; ++iter)
	{
		if((*iter).loop == loop && (*iter).mode == mode && (*iter).model_id == item_model)
		{// 局数相同，房费类型数量相同，游戏玩法相同
			return *iter;
		}
	}
	
	return stCBOC;
}

// 获得组局模式名称
String XmlDataManager::GetCenterBattleGameModeName(const uint32 & agent_id, const uint32 & game_id, const uint8 & mode)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, std::vector<stCenterBattleOpenCoins> > >::iterator fit = m_mapCenterBattleOpenCoins.find(agent_id);
	if(fit == m_mapCenterBattleOpenCoins.end())
		fit = m_mapCenterBattleOpenCoins.find(0);
	
	if(fit == m_mapCenterBattleOpenCoins.end())
		return "";
	
	std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator fit2 = fit->second.find(game_id);
	if(fit2 == fit->second.end())
		return "";
	
	std::vector<stCenterBattleOpenCoins>::iterator iter,ei = fit2->second.end();
	for(iter = fit2->second.begin(); iter!=ei; ++iter)
	{
		if((*iter).mode == mode)
		{// 局数相同，房费类型数量相同，游戏玩法相同
			return (*iter).desc;
		}
	}
	
	return "";
}

std::map<uint32, std::vector<stCenterBattleOpenCoins> > XmlDataManager::GetOpenCoinsTotalInfo(const uint32 & agent_id)
{
	std::map<uint32, std::vector<stCenterBattleOpenCoins> > mapOpenCoins;
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, std::vector<stCenterBattleOpenCoins> > >::iterator fit = m_mapCenterBattleOpenCoins.find(agent_id);
	if(fit == m_mapCenterBattleOpenCoins.end())
		fit = m_mapCenterBattleOpenCoins.find(0);
	
	if(fit == m_mapCenterBattleOpenCoins.end())
		return mapOpenCoins;
	
	std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator iter, ei = fit->second.end();
	for(iter = fit->second.begin(); iter!=ei; ++iter)
	{
		std::vector<stCenterBattleOpenCoins>::iterator itOp, eiOp = iter->second.end();
		for(itOp = iter->second.begin(); itOp!=eiOp; ++itOp)
		{
			if((*itOp).free_mode)
			{
				std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator fit2 = mapOpenCoins.find(iter->first);
				if(fit2 == mapOpenCoins.end())
				{
					std::vector<stCenterBattleOpenCoins> vOp;
					vOp.push_back(*itOp);
					
					mapOpenCoins.insert(std::make_pair(iter->first, vOp));
				}
				else
				{
					fit2->second.push_back(*itOp);
				}
			}
		}
	}
	
	return mapOpenCoins;
}

// 判断某个玩法是否支持某个平台
bool XmlDataManager::IsPfInCenterBattleMode(const uint32 & agent_id, const uint32 & game_id, const uint32 & value, const uint8 & mode, String strPf)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, std::vector<stCenterBattleOpenCoins> > >::iterator fit = m_mapCenterBattleOpenCoins.find(agent_id);
	if(fit == m_mapCenterBattleOpenCoins.end())
		fit = m_mapCenterBattleOpenCoins.find(0);
	
	if(fit == m_mapCenterBattleOpenCoins.end())
		return false;
	
	std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator fit2 = fit->second.find(game_id);
	if(fit2 == fit->second.end())
		return false;
	
	std::vector<String> vPfs;
	std::vector<stCenterBattleOpenCoins>::iterator iter,ei = fit2->second.end();
	for(iter = fit2->second.begin(); iter!=ei; ++iter)
	{
		if((*iter).loop == value && (*iter).mode == mode)
		{
			vPfs = (*iter).vPfs;
			break;
		}
	}
	
	std::vector<String>::iterator itPf, eiPf = vPfs.end();
	for(itPf = vPfs.begin(); itPf!=eiPf; ++itPf)
	{
		if(!strPf.compare(*itPf))
		{
			return true;
		}
	}
	
	return false;
}

// 获得某个游戏的观战标志
uint32 XmlDataManager::GetGameWatchMode(const uint32 & agent_id, const uint32 & game_id, const uint32 & item_model, const uint32 & mode, const uint32 & loop)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, std::vector<stCenterBattleOpenCoins> > >::iterator fit = m_mapCenterBattleOpenCoins.find(agent_id);
	if(fit == m_mapCenterBattleOpenCoins.end())
		fit = m_mapCenterBattleOpenCoins.find(0);
	
	if(fit == m_mapCenterBattleOpenCoins.end())
		return 0;
	
	std::map<uint32, std::vector<stCenterBattleOpenCoins> >::iterator fit2 = fit->second.find(game_id);
	if(fit2 == fit->second.end())
		return 0;
	
	std::vector<stCenterBattleOpenCoins>::iterator iter,ei = fit2->second.end();
	for(iter = fit2->second.begin(); iter!=ei; ++iter)
	{
		if((*iter).loop == loop && (*iter).mode == mode && (*iter).model_id == item_model)
		{// 局数相同，房费类型数量相同，游戏玩法相同
			return (*iter).watch;
		}
	}
	
	return 0;
}

// 加载游戏ID配置
bool XmlDataManager::LoadGameIdsXml(void)
{
	char strPath[512] = "";
	sprintf(strPath, "%s/my_gameids.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	// TiXmlDocument doc("../scripts_xml/my_gameids.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load my_gameids.xml failed!");
		return false;
	}

WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "my_gameids.xml have not root node!");
		return false;
	}
	
	m_vGameIDs.clear();
	
	Log.Debug("XmlDataManager init", "Start load %s", strPath);
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		m_vGameIDs.push_back(StringConverter::parseUnsignedInt(child->Attribute("game_id")));
		child = child->NextSiblingElement();
	}
	
	Log.Error("load XML Error", "load my_gameids.xml sucess size[%u]!", m_vGameIDs.size());
	return true;
}

bool XmlDataManager::ReLoadGameIdsXml(void)
{
	return LoadGameIdsXml();
}

// 检测游戏ID是否存在配置中
bool XmlDataManager::IsInGameIds(const uint32 & game_id)
{
WGS_XML_WRITE_LOCK
	std::vector<uint32>::iterator iter,ei = m_vGameIDs.end();
	for(iter = m_vGameIDs.begin(); iter!=ei; ++iter)
	{
		if(*iter == game_id)	// 找到分区
			return true;
	}
	
	return false;
}

// 加载棋牌圈模式对应城市ID和AI配置
bool XmlDataManager::LoadCenterBattleModeXml(void)
{
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/centerbattle_modeai.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load centerbattle_modeai.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "centerbattle_modeai.xml have not root node!");
		return false;
	}
	
WGS_XML_WRITE_LOCK

	m_mapCenterBattleMode.clear();
	while(pRoot)
	{
		uint32 game_id = StringConverter::parseUnsignedInt(pRoot->Attribute("game_id"));
		std::vector<stCenterBattleMode> vCBM;
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			stCenterBattleMode stCBM;
			stCBM.mode = StringConverter::parseUnsignedInt(child->Attribute("mode"));
			stCBM.town_id = StringConverter::parseUnsignedInt(child->Attribute("town_id"));
			stCBM.ai = StringConverter::parseUnsignedInt(child->Attribute("ai"));
			stCBM.game_id = game_id;
			
			vCBM.push_back(stCBM);
			child = child->NextSiblingElement();
		}
		
		m_mapCenterBattleMode.insert(std::make_pair(game_id, vCBM));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("LoadCenterBattleModeXml","Load centerbattle_modeai.xml size[%u] sucess!", m_mapCenterBattleMode.size());
	return true;
}

// 重载棋牌圈模式对应AI配置
bool XmlDataManager::ReLoadCenterBattleModeXml(void)
{
	return LoadCenterBattleModeXml();
}

// 获取棋牌圈游戏模式对应AI配置
stCenterBattleMode XmlDataManager::GetCenterBattleModeByGameid(const uint32 & game_id,  const uint8 & mode)
{
WGS_XML_WRITE_LOCK
	stCenterBattleMode stCBM;
	std::map<uint32, std::vector<stCenterBattleMode> >::iterator fit = m_mapCenterBattleMode.find(game_id);
	if(fit == m_mapCenterBattleMode.end())
		return stCBM;
	
	std::vector<stCenterBattleMode>::iterator iter, ei = fit->second.end();
	for(iter = fit->second.begin(); iter!=ei; ++iter)
	{
		if(mode == (*iter).mode)
		{
			return *iter;
		}
	}
	
	return stCBM;
}

// AI号是否属于棋牌圈
bool XmlDataManager::IsAIInCenterBattle(const uint32 & game_id, const uint32 & ai)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, std::vector<stCenterBattleMode> >::iterator fit = m_mapCenterBattleMode.find(game_id);
	if(fit == m_mapCenterBattleMode.end())
		return false;
	
	std::vector<stCenterBattleMode>::iterator iter, ei = fit->second.end();
	for(iter = fit->second.begin(); iter!=ei; ++iter)
	{
		if((*iter).ai == ai)
			return true;
	}
	
	return false;
}

// 加载评价标签ID配置
bool XmlDataManager::LoadCenterJudgeLabelIDXml(void)
{
WGS_XML_WRITE_LOCK
	TiXmlDocument doc("../scripts_xml/judge_label_id.xml");	
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load judge_label_id.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "judge_label_id.xml have not root node!");
		return false;
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/judge_label_id.xml");
	m_mapJudgeLabelID.clear();
	
	while(pRoot)
	{
		uint32 label_id = StringConverter::parseUnsignedInt(pRoot->Attribute("label_id"));
		String strDesc = pRoot->Attribute("desc");
		m_mapJudgeLabelID.insert(std::make_pair(label_id, strDesc));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager init", "Start load ../scripts_xml/judge_label_id.xml successfully");
	return true;
}

bool XmlDataManager::ReLoadCenterJudgeLabelIDXml(void)
{
	return LoadCenterJudgeLabelIDXml();
}

// 判断评价标签ID是否存在
bool XmlDataManager::IsJudgeLabelIDExist(const uint32 & label_id)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, String>::iterator fit = m_mapJudgeLabelID.find(label_id);
	if(fit == m_mapJudgeLabelID.end())
		return false;
	
	return true;
}

// 获得标签名称
String XmlDataManager::GetJudgeLabelNameByID(const uint32 & label_id)
{
	std::map<uint32, String>::iterator fit = m_mapJudgeLabelID.find(label_id);
	if(fit == m_mapJudgeLabelID.end())
		return "";
	
	return fit->second;
}

// 加载打包商品配置
bool XmlDataManager::LoadBuyUnionGoodsXml(void)
{
	TiXmlDocument doc("../scripts_xml/buy_union_goods.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadBuyUnionGoodsXml", "load buy_union_goods.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("XmlDataManager::LoadBuyUnionGoodsXml", "buy_union_goods.xml have not root node!");
		return false;
	}
	
	m_mapUnionGoods.clear();
	while(pRoot)
	{
		stBuyUnionGoods buyGoods;
		if (pRoot->HasAttribute("id")){
			buyGoods.id = StringConverter::parseUnsignedInt(pRoot->Attribute("id"));
		}
		if (pRoot->HasAttribute("name")){
			buyGoods.name = pRoot->Attribute("name");
		}
		if (pRoot->HasAttribute("type")){
			buyGoods.type = StringConverter::parseUnsignedInt(pRoot->Attribute("type"));
		}
		if (pRoot->HasAttribute("items")){
			buyGoods.items = pRoot->Attribute("items");
		}
		
		m_mapUnionGoods.insert(std::make_pair(buyGoods.id, buyGoods));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadBuyUnionGoodsXml", "load vipcards.xml successfully m_mapUnionGoods[%u]!", m_mapUnionGoods.size());
	return true;
}

bool XmlDataManager::ReloadBuyUnionGoodsXml(void)
{
WGS_XML_WRITE_LOCK
	return LoadBuyUnionGoodsXml();
}

// 获得打包礼品配置
stBuyUnionGoods XmlDataManager::GetUnionGoodsByID(const uint32 & goods_id)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, stBuyUnionGoods>::iterator fit = m_mapUnionGoods.find(goods_id);
	if(fit != m_mapUnionGoods.end())
		return fit->second;
	
	stBuyUnionGoods stBUG;	// 莫名的喜感
	return stBUG;
}
	
bool XmlDataManager::LoadCommonOnlineGiftXml(void)
{
	char strPath[512] = "";
	sprintf(strPath, "%s/common_online_gift.xml", _GAME_XMLFILE_PATH_);
	
	TiXmlDocument doc(strPath);
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load common_online_gift.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "common_online_gift.xml have not root node!");
		return false;
	}
	
WGS_XML_WRITE_LOCK
	
	m_stCommonGift.Init();
	while(pRoot)
	{
		// 日常
		m_stCommonGift.isDaily = StringConverter::parseUnsignedInt(pRoot->Attribute("daily"));
		// 同时计时
		m_stCommonGift.isSameTime = StringConverter::parseUnsignedInt(pRoot->Attribute("same_time"));
		// 角色user_data键
		m_stCommonGift.strOnlineKey = pRoot->Attribute("online_key");
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			stCommonSingleGift stCSG;
			stCSG.id = StringConverter::parseUnsignedInt(child->Attribute("id"));
			stCSG.seconds = StringConverter::parseUnsignedInt(child->Attribute("seconds"));
			stCSG.coins = StringConverter::parseUnsignedInt(child->Attribute("coins"));
			
			m_stCommonGift.mapGift.insert(std::make_pair(stCSG.id, stCSG));
			child = child->NextSiblingElement();
		}
		
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("LoadCenterBattleModeXml","Load common_online_gift.xml size[%u] sucess!", m_mapCenterBattleMode.size());
	return true;
}

bool XmlDataManager::ReLoadCommonOnlineGiftXml(void)
{
	return LoadCommonOnlineGiftXml();
}

// 加载网关原因配置
bool XmlDataManager::LoadGatewayResonXml(void)
{
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/gateway_reson_code.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load gateway_reson_code.xml failed!");
		return false;
	}
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "gateway_reson_code.xml have not root node!");
		return false;
	}

WGS_XML_WRITE_LOCK
	m_mapGatewayReson.clear();
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		uint32 reson_id = StringConverter::parseUnsignedInt(child->Attribute("reson_id"));
		String strReson = child->Attribute("desc");
		
		m_mapGatewayReson.insert(std::make_pair(reson_id, strReson));
		child = child->NextSiblingElement();
	}
	
	return true;
}

bool XmlDataManager::ReLoadGatewayResonXml(void)
{
	return LoadGatewayResonXml();
}

// 获得网关原因内容
String XmlDataManager::GetGatewayReson(const uint32 & reson_id)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, String>::iterator fit = m_mapGatewayReson.find(reson_id);
	if(fit != m_mapGatewayReson.end())
		return fit->second;
	
	return "";
}


bool XmlDataManager::LoadItemModelNameXml(void)
{
WGS_XML_WRITE_LOCK
	TiXmlDocument doc("../scripts_xml/item_model_name.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load item_model_name.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "item_model_name.xml have not root node!");
		return false;
	}
	
	m_mapItemModelName.clear();
	
	while(pRoot)
	{
		uint32 agent_id = StringConverter::parseUnsignedInt(pRoot->Attribute("agent_id"));
		std::map<uint32, String> mapItemName;
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			uint32 model_id = StringConverter::parseUnsignedInt(child->Attribute("model_id"));
			String strName = child->Attribute("name");
			
			mapItemName.insert(std::make_pair(model_id, strName));
			child = child->NextSiblingElement();
		}
		
		m_mapItemModelName.insert(std::make_pair(agent_id, mapItemName));
		pRoot = pRoot->NextSiblingElement();
	}
	
	return true;
}

bool XmlDataManager::ReLoadItemModelNameXml(void)
{
	return LoadItemModelNameXml();
}

// 获得代理商物品名称
String XmlDataManager::GetItemModelNameByAgentID(const uint32 & agent_id, const uint32 & item_modelid)
{
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, String> >::iterator fit = m_mapItemModelName.find(agent_id);
	if(fit == m_mapItemModelName.end())
	{
		fit = m_mapItemModelName.find(0);
		if(fit == m_mapItemModelName.end())
			return "";
	}
	
	std::map<uint32, String>::iterator fit_name = fit->second.find(item_modelid);
	if(fit_name != fit->second.end())
		return fit_name->second;
	
	return "";
}

// 加载赠送道具配置
bool XmlDataManager::LoadRegisterGiveItemsXml(void)
{
	TiXmlDocument doc("../scripts_xml/register_give_items.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load register_give_items.xml failed!");
		return false;
	}
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "register_give_items.xml have not root node!");
		return false;
	}
	
	m_mapRegisterGiveItems.clear();
	
	while(pRoot)
	{
		uint32 agent_id = StringConverter::parseUnsignedInt(pRoot->Attribute("agent_id"));
		std::map<uint32, uint32> mapItems;
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			uint32 model_id = StringConverter::parseUnsignedInt(child->Attribute("model_id"));
			uint32 num = StringConverter::parseUnsignedInt(child->Attribute("num"));
			
			mapItems.insert(std::make_pair(model_id, num));
			child = child->NextSiblingElement();
		}
		
		m_mapRegisterGiveItems.insert(std::make_pair(agent_id, mapItems));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadRegisterGiveItemsXml","load register_give_items.xml sucess!");
	return true;
}

bool XmlDataManager::ReLoadRegisterGiveItemsXml(void)
{
	return LoadRegisterGiveItemsXml();
}

std::map<uint32, uint32> XmlDataManager::GetRegisterGiveItems(const uint32 & agent_id)
{
	std::map<uint32, uint32> mapItems;
	
WGS_XML_WRITE_LOCK
	std::map<uint32, std::map<uint32, uint32> >::iterator fitAgent = m_mapRegisterGiveItems.find(agent_id);
	if(fitAgent != m_mapRegisterGiveItems.end())
	{
		return fitAgent->second;
	}
	else
	{
		fitAgent = m_mapRegisterGiveItems.find(0);
		if(fitAgent != m_mapRegisterGiveItems.end())
		{
			return fitAgent->second;
		}
		else
		{
			return mapItems;
		}
	}
	
	return mapItems;
}

//---------------------棋牌圈比赛--------------------------------

bool XmlDataManager::LoadCenterMatchModeInfo(void)
{
	WGS_XML_WRITE_LOCK;

	char strPath[512] = "";
	sprintf(strPath, "../scripts_xml/CenterMatchModeInfo.xml");
	TiXmlDocument doc(strPath);

	if (!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadCenterMatchModeInfo", "load CenterMatchModeInfo.xml failed!");
		return false;
	}

	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("XmlDataManager::LoadCenterMatchModeInfo", "CenterMatchModeInfo.xml have not root node!");
		return false;
	}
	TiXmlElement* pNode = pRoot->FirstChildElement();
	if (NULL == pNode)
	{
		Log.Error("XmlDataManager::LoadCenterMatchModeInfo", "CenterMatchModeInfo.xml have not root node!");
		return false;
	}
	CenterMatchModeInfoMap.clear();

	while (pNode)
	{
		uint32 agent_id = 0;
		if (pNode->HasAttribute("agent_id"))
		{
			agent_id = StringConverter::parseUnsignedInt(pNode->Attribute("agent_id"));
		}
		if (agent_id == 0)
		{
			pNode = pNode->NextSiblingElement();
			Log.Error("XmlDataManager::LoadCenterMatchModeInfo", "agent_id == 0");
			continue;
		}
		std::vector<stCenterMatchModeInfo> CenterMatchModeInfoList;
		TiXmlElement* pChild = pNode->FirstChildElement();
		while (pChild)
		{
			stCenterMatchModeInfo CenterMatchModeInfo;
			CenterMatchModeInfo.agent_id = agent_id;
			stCenterMatchStage StageTemp;
			if (pChild->HasAttribute("game_id"))
			{//比赛模式id
				CenterMatchModeInfo.game_id = StringConverter::parseUnsignedInt(pChild->Attribute("game_id"));
			}
			if (pChild->HasAttribute("mode_id"))
			{//比赛模式id
				CenterMatchModeInfo.matchMode = StringConverter::parseUnsignedInt(pChild->Attribute("mode_id"));
			}
			 if (pChild->HasAttribute("each_channel_player"))
			{//每桌玩家人数
				CenterMatchModeInfo.eachChannelPlayer = StringConverter::parseUnsignedInt(pChild->Attribute("each_channel_player"));
			}
			 if (pChild->HasAttribute("min_match_channel"))
			{//最低开赛桌数
				CenterMatchModeInfo.min_math_begin_channel = StringConverter::parseUnsignedInt(pChild->Attribute("min_match_channel"));
			}
			 if (pChild->HasAttribute("min_player"))
			{//最低开赛人数
				CenterMatchModeInfo.min_math_begin_num = StringConverter::parseUnsignedInt(pChild->Attribute("min_player"));
			}
			 if (pChild->HasAttribute("limit_match_num"))
			{//最低匹配开始人数
				CenterMatchModeInfo.limit_match_num = StringConverter::parseUnsignedInt(pChild->Attribute("limit_match_num"));
			}
			 if (pChild->HasAttribute("no_channel_overtime"))
			{//无比赛自动结束时间
				CenterMatchModeInfo.no_channel_over_time = StringConverter::parseUnsignedInt(pChild->Attribute("no_channel_overtime"));
			}
			
			TiXmlElement * pStage = pChild->FirstChildElement();
			while (pStage)
			{
				if (pStage->HasAttribute("index"))
				{//阶段序号
					StageTemp.stageNumber = StringConverter::parseUnsignedInt(pStage->Attribute("index"));
				}
				if (pStage->HasAttribute("stagemode"))
				{//阶段赛制
					StageTemp.stageMode = StringConverter::parseUnsignedInt(pStage->Attribute("stagemode"));
				}
				TiXmlElement * pStageNode = pStage->FirstChildElement();
				while (pStageNode)
				{
					if (strcmp(pStageNode->Value(), "init_score") == 0)
					{//初始分数
						StageTemp.init_score = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "limit_time") == 0)
					{//阶段限制时间
						StageTemp.limit_time = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "channel_limit_loop") == 0)
					{//阶段牌桌局数
						StageTemp.channel_limit_loop = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "base_score") == 0)
					{//初始底分
						StageTemp.base_score = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "eliminate_score") == 0)
					{//初始淘汰分数
						StageTemp.eliminate = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "eliminate_mode") == 0)
					{//初始淘汰分数
						StageTemp.eliminateMode = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "eliminate_increase") == 0)
					{//淘汰分数增长
						stEliminateIncrease temp;
						temp.eliminate = StringConverter::parseUnsignedInt(pStageNode->Attribute("eliminate"));
						temp.base = StringConverter::parseUnsignedInt(pStageNode->Attribute("base"));
						temp.timeUp = StringConverter::parseUnsignedInt(pStageNode->Attribute("time"));
						StageTemp.EliminateIncrease.push_back(temp);
					}
					else if (strcmp(pStageNode->Value(), "end_condition") == 0)
					{//淘汰分数增长
						stEndCondition temp;
						temp.min = StringConverter::parseUnsignedInt(pStageNode->Attribute("min"));
						temp.max = StringConverter::parseUnsignedInt(pStageNode->Attribute("max"));
						temp.endType = StringConverter::parseUnsignedInt(pStageNode->Attribute("end_typ"));
						temp.endNumber = StringConverter::parseUnsignedInt(pStageNode->Attribute("end_number"));
						StageTemp.EndConditionList.push_back(temp);
					}
					else if (strcmp(pStageNode->Value(), "nextround") == 0)
					{//晋级人数
						StageTemp.stageRule = pStageNode->Attribute("value");
					}
					else if (strcmp(pStageNode->Value(), "init_score_scaling") == 0)
					{//初始分数缩放
						StageTemp.init_score_scaling = StringConverter::parseDouble(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "score_scaling") == 0)
					{//分数缩放
						StageTemp.score_scaling = StringConverter::parseDouble(pStageNode->Attribute("value"));
					}
					else if (strcmp(pStageNode->Value(), "stage_loop") == 0)
					{//每次游戏轮数
						StageTemp.stage_loop = StringConverter::parseUnsignedInt(pStageNode->Attribute("value"));
					}
					pStageNode = pStageNode->NextSiblingElement();
				}

				CenterMatchModeInfo.matchStage.push_back(StageTemp);
				pStage = pStage->NextSiblingElement();
			}

			Log.Success("XmlDataManager::LoadCenterMatchModeInfo", "agent_id[%d] matchMode[%d] eachChannelPlayer[%d]", CenterMatchModeInfo.agent_id,CenterMatchModeInfo.matchMode,CenterMatchModeInfo.eachChannelPlayer);
			CenterMatchModeInfoList.push_back(CenterMatchModeInfo);
			pChild = pChild->NextSiblingElement();
		}
		CenterMatchModeInfoMap.insert(std::make_pair(agent_id, CenterMatchModeInfoList));


		pNode = pNode->NextSiblingElement();
	}
	return true;
}

bool XmlDataManager::ReLoadCenterMatchModeInfo(void)
{
	return LoadRegisterGiveItemsXml();
}

stCenterMatchModeInfo XmlDataManager::GetCenterMatchModeInfo(const uint32 &  agent_id, const uint8 & mode_id)
{
	WGS_XML_WRITE_LOCK;
	stCenterMatchModeInfo temp;
	if (CenterMatchModeInfoMap.find(agent_id) == CenterMatchModeInfoMap.end())
		return temp;
	std::map<uint32, std::vector<stCenterMatchModeInfo > >::iterator  iter =  CenterMatchModeInfoMap.find(agent_id);
	for (uint32 i = 0; i < iter->second.size(); i++)
	{
		if (iter->second[i].matchMode == mode_id )
		{
			temp = iter->second[i];
		}
	}
	return temp;
}

bool XmlDataManager::LoadCommonActivity(void)
{
	TiXmlDocument doc("../scripts_xml/activity.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load activity.xml failed!");
		return false;
	}
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "register_give_items.xml have not root node!");
		return false;
	}
	
	m_mapCommonActivity.clear();
	while(pRoot)
	{
		uint32 agent_id = StringConverter::parseUnsignedInt(pRoot->Attribute("agent_id"));
		std::vector<stCommonActivity> vActivity;
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			stCommonActivity acti;
			
			acti.type = StringConverter::parseUnsignedInt(child->Attribute("type"));
			acti.need_count = StringConverter::parseUnsignedInt(child->Attribute("need_count"));
			acti.finish_count = StringConverter::parseUnsignedInt(child->Attribute("finish_count"));
			acti.daily = StringConverter::parseUnsignedInt(child->Attribute("daily"));
			
			String strBeginTime = child->Attribute("begin_time");
			String strEndTime = child->Attribute("end_time");
			
			acti.begin_time = sTools.GetDateTimeSeconds(strBeginTime);
			acti.end_time = sTools.GetDateTimeSeconds(strEndTime);
			Log.Debug("XmlDataManager::LoadCommonActivity","agent_id[%u] begin_time[%u] end_time[%u] type[%u]", agent_id, acti.begin_time, acti.end_time, acti.type);
			std::vector<String> vStr = StringUtil::split(child->Attribute("bounties"), ",");
			if(vStr.size())
			{
				std::vector<String>::iterator iter, ei = vStr.end();
				for(iter = vStr.begin(); iter!=ei; ++iter)
				{
					std::vector<String> vStr2 = StringUtil::split(*iter, ":");
					acti.mapBounties.insert(std::make_pair(StringConverter::parseUnsignedInt(vStr2[0]), StringConverter::parseUnsignedInt(vStr2[1])));
				}
			}
			
			vActivity.push_back(acti);
			child = child->NextSiblingElement();
		}
		
		Log.Debug("XmlDataManager::LoadCommonActivity","agent_id[%u] vActivity[%u]", agent_id, vActivity.size());
		m_mapCommonActivity.insert(std::make_pair(agent_id, vActivity));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadCommonActivity","load activity.xml sucess!");
	return true;
}

bool XmlDataManager::ReLoadCommonActivity(void)
{
	return LoadCommonActivity();
}

stCommonActivity XmlDataManager::GetCommonActivity(const uint32 &  agent_id, const uint32 & type)
{
	stCommonActivity acti;
WGS_XML_WRITE_LOCK
	Log.Debug("XmlDataManager::GetCommonActivity","agent_id[%u] 111", agent_id);
	std::map<uint32, std::vector<stCommonActivity> >::iterator fit = m_mapCommonActivity.find(agent_id);
	if(fit == m_mapCommonActivity.end())
		return acti;
	Log.Debug("XmlDataManager::GetCommonActivity","agent_id[%u] 222", agent_id);
	std::vector<stCommonActivity>::iterator iter, ei = fit->second.end();
	for(iter = fit->second.begin(); iter!=ei; ++iter)
	{
		Log.Debug("XmlDataManager::GetCommonActivity","iter type[%u] type[%u]", (*iter).type, type);
		if((*iter).type == type)
			return *iter;
	}
	
	return acti;
}

// 签到相关
bool XmlDataManager::LoadCommonSignInfoXml(void)
{
	TiXmlDocument doc("../scripts_xml/sign_info.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load sign_info.xml failed!");
		return false;
	}
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "sign_info.xml have not root node!");
		return false;
	}
	
	m_vCommonSign.clear();
	while(pRoot)
	{
		stCommonSignInfo si;
		si.agent_id = StringConverter::parseUnsignedInt(pRoot->Attribute("agent_id"));						// 代理商ID
		si.gz_id = StringConverter::parseUnsignedInt(pRoot->Attribute("gz_id"));							// 分区ID
		si.sign_mode = StringConverter::parseUnsignedInt(pRoot->Attribute("sign_mode"));					// 签到模式
		si.sign_sub_mode = StringConverter::parseUnsignedInt(pRoot->Attribute("sign_sub_mode"));			// 签到子模式
		si.update_combo_mode = StringConverter::parseUnsignedInt(pRoot->Attribute("update_combo_mode"));	// 签到更新模式
		si.update_bounty_mode = StringConverter::parseUnsignedInt(pRoot->Attribute("update_bounty_mode"));	// 奖励更新模式
		si.agent_name = pRoot->Attribute("agent_name");														// 代理商名称
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			stCommonSingleSignInfo ssi;
			// 周
			if(child->HasAttribute("week"))
				ssi.week = StringConverter::parseUnsignedInt(child->Attribute("week"));
			
			// 月
			if(child->HasAttribute("month"))
				ssi.month = StringConverter::parseUnsignedInt(child->Attribute("month"));
			
			// 日
			if(child->HasAttribute("day"))
				ssi.day = StringConverter::parseUnsignedInt(child->Attribute("day"));
			
			// 天数
			if(child->HasAttribute("days"))
				ssi.days = StringConverter::parseUnsignedInt(child->Attribute("days"));
			
			// 描述
			if(child->HasAttribute("desc"))
				ssi.desc = child->Attribute("desc");
			
			// 奖励
			if(child->HasAttribute("bounties"))
			{
				std::vector<String> vStr = StringUtil::split(child->Attribute("bounties"), ",");
				if(vStr.size())
				{
					std::vector<String>::iterator iter, ei = vStr.end();
					for(iter = vStr.begin(); iter!=ei; ++iter)
					{
						std::vector<String> vStr2 = StringUtil::split(*iter, ":");
						ssi.mapBounties.insert(std::make_pair(StringConverter::parseUnsignedInt(vStr2[0]), StringConverter::parseUnsignedInt(vStr2[1])));
					}
				}
			}
			
			if(!String(child->Value()).compare("data"))
			{// 签到信息节点
				si.vSignInfo.push_back(ssi);
			}
			else if(!String(child->Value()).compare("combo"))
			{// 连签节点
				si.vComboInfo.push_back(ssi);
			}
			else if(!String(child->Value()).compare("count"))
			{// 累签节点
				si.vCountInfo.push_back(ssi);
			}
			
			child = child->NextSiblingElement();
		}
		
		Log.Notice("LoadCommonSignInfoXml","vSignInfo[%u] vComboInfo[%u] vCountInfo[%u] update_bounty_mode[%u]", si.vSignInfo.size(), si.vComboInfo.size(), si.vCountInfo.size(), si.update_bounty_mode);
		m_vCommonSign.push_back(si);
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadCommonSignInfoXml","load sign_info xml sucess!");
	return true;
}

bool XmlDataManager::ReLoadCommonSignInfoXml(void)
{
	return LoadCommonSignInfoXml();
}

stCommonSignInfo XmlDataManager::GetCommonSignInfo(const uint32 & agent_id, const uint32 & gz_id)
{
	stCommonSignInfo temp;
WGS_XML_WRITE_LOCK
	std::vector<stCommonSignInfo>::iterator iter, ei = m_vCommonSign.end();
	for(iter = m_vCommonSign.begin(); iter!=ei; ++iter)
	{
		if((*iter).agent_id == agent_id)
		{
			if((*iter).gz_id && (*iter).gz_id != gz_id)
				continue;
			
			return *iter;
		}
	}
	
	return temp;
}

// 创建成就相关
bool XmlDataManager::LoadBuildEffortsXml(void)
{
	TiXmlDocument doc("../scripts_xml/build_common_effects.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load build_common_effects.xml failed!");
		return false;
	}
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "build_common_effects.xml have not root node!");
		return false;
	}
	
	m_mapBuildEfforts.clear();
	
	while(pRoot)
	{
		stBuildEfforts stBE;
		stBE.agent_id = StringConverter::parseUnsignedInt(pRoot->Attribute("agent_id"));
		stBE.tt_effortid = StringConverter::parseUnsignedInt(pRoot->Attribute("tt_effortid"));
		stBE.agent_name = pRoot->Attribute("agent_name");
		
		if(pRoot->HasAttribute("daily"))	// 日常
			stBE.daily = StringConverter::parseUnsignedInt(pRoot->Attribute("daily"));
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			stSignleEffortInfo stSEI;
			
			if(child->Attribute("model_id"))
				stSEI.model_id = StringConverter::parseUnsignedInt(child->Attribute("model_id"));		// 模式ID
			
			if(child->Attribute("type"))
				stSEI.type = StringConverter::parseUnsignedInt(child->Attribute("type"));				// 类型
			
			if(child->Attribute("gz_id"))
				stSEI.gz_id = StringConverter::parseUnsignedInt(child->Attribute("gz_id"));				// 分区ID
			
			if(child->Attribute("data_gz_id"))
				stSEI.data_gz_id = StringConverter::parseUnsignedInt(child->Attribute("data_gz_id"));	// 数据存储分区
			
			if(child->Attribute("need_count"))
				stSEI.need_count = StringConverter::parseUnsignedInt(child->Attribute("need_count"));	// 完成需要次数
			
			if(child->Attribute("extra_data1"))
				stSEI.extra_data1 = StringConverter::parseUnsignedInt(child->Attribute("extra_data1"));	// 附加判定条件1
			
			if(child->Attribute("daily"))
				stSEI.daily = StringConverter::parseUnsignedInt(child->Attribute("daily"));			// 完成需要次数
			
			if(child->Attribute("desc"))
				stSEI.name = child->Attribute("desc");												// 成就名称
			
			if(child->Attribute("content"))
				stSEI.content = child->Attribute("content");										// 成就内容
			
			if(child->Attribute("bounty"))
			{// 奖励
				std::vector<String> vStr = StringUtil::split(child->Attribute("bounty"), ",");
				if(vStr.size())
				{
					std::vector<String>::iterator iter, ei = vStr.end();
					for(iter = vStr.begin(); iter!=ei; ++iter)
					{
						std::vector<String> vStr2 = StringUtil::split(*iter, ":");
						stSEI.mapBounties.insert(std::make_pair(StringConverter::parseUnsignedInt(vStr2[0]), StringConverter::parseUnsignedInt(vStr2[1])));
					}
				}
			}
			
			stBE.vEfforts.push_back(stSEI);
			stBE.effect_models.push_back(StringConverter::parseUnsignedInt(child->Attribute("model_id")));
			Log.Debug("XmlDataManager::LoadBuildEffortsXml","model_id[%u] stBE.daily[%u]", StringConverter::parseUnsignedInt(child->Attribute("model_id")), stBE.daily);
			child = child->NextSiblingElement();
		}
		
		
		Log.Debug("XmlDataManager::LoadBuildEffortsXml","agent_id[%u] effect_models[%u]", stBE.agent_id, stBE.effect_models.size());
		m_mapBuildEfforts.insert(std::make_pair(stBE.agent_id, stBE));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadBuildEffortsXml","load build_common_effects.xml sucess!");
	return true;
}

bool XmlDataManager::ReLoadBuildEffortsXml(void)
{
	return LoadBuildEffortsXml();
}

stBuildEfforts XmlDataManager::GetBuildEfforts(const uint32 & agent_id)
{
	stBuildEfforts temp;
	
WGS_XML_WRITE_LOCK
	std::map<uint32, stBuildEfforts>::iterator fit = m_mapBuildEfforts.find(agent_id);
	if(fit != m_mapBuildEfforts.end())
		return fit->second;
	
	return temp;
}

std::vector<stSignleEffortInfo> XmlDataManager::GetBuildEffortsStructVector(const uint32 & agent_id)
{
	std::vector<stSignleEffortInfo> vInfo;
	std::map<uint32, stBuildEfforts>::iterator fit = m_mapBuildEfforts.find(agent_id);
	if(fit == m_mapBuildEfforts.end())
		return vInfo;
	
	return fit->second.vEfforts;
}


// 网关域名相关
bool XmlDataManager::LoadGatewayHttpHoseAddr(void)
{
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/gateway_httphost.xml");
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load gateway_httphost.xml failed!");
		return false;
	}

WGS_XML_READ_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "gateway_httphost.xml have not root node!");
		return false;
	}
	
	m_mapGatewayHttpHostAddr.clear();
	
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		uint32 agent_id = StringConverter::parseUnsignedInt(child->Attribute("agent_id"));
		String strAddr = child->Attribute("addr");
		
		m_mapGatewayHttpHostAddr.insert(std::make_pair(agent_id, strAddr));
		child = child->NextSiblingElement();
	}
	
	Log.Debug("load XML Error","load gateway_httphost.xml sucess size[%i]!", m_mapGatewayHttpHostAddr.size());
	return true;
}

bool XmlDataManager::ReLoadGatewayHttpHoseAddr(void)
{
	return LoadGatewayHttpHoseAddr();
}

String XmlDataManager::GetGatewayHttpHostAddr(const uint32 & agent_id)
{
WGS_XML_READ_LOCK
	std::map<uint32, String>::iterator fit = m_mapGatewayHttpHostAddr.find(agent_id);
	if(fit == m_mapGatewayHttpHostAddr.end())
		fit = m_mapGatewayHttpHostAddr.find(0);
	
	if(fit != m_mapGatewayHttpHostAddr.end())
		return fit->second;
	
	return "";
}

// 比赛积分配置
bool XmlDataManager::LoadMatchOrderScoreXml(void)
{
	// TiXmlDocument doc(strPath);
	TiXmlDocument doc("../scripts_xml/match_order_score.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadMatchOrderScoreXml", "load match_order_score.xml failed!");
		return false;
	}

WGS_XML_READ_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("XmlDataManager::LoadMatchOrderScoreXml", "match_order_score.xml have not root node!");
		return false;
	}
	
	m_vMarchOrderScore.clear();
	
	TiXmlElement* child = pRoot->FirstChildElement();
	while(child)
	{
		stMatchOrderScore stMOS;
		
		stMOS.min_p = StringConverter::parseUnsignedInt(child->Attribute("min_p"));
		stMOS.max_p = StringConverter::parseUnsignedInt(child->Attribute("max_p"));
		
		String strScore = child->Attribute("score");
		std::vector<String> vStrScore = StringUtil::split(strScore, ",");	// 1-1:26.0
		std::vector<String>::iterator iter, ei = vStrScore.end();
		for(iter = vStrScore.begin(); iter!=ei; ++iter)
		{
			stOrderScore stOS;
			
			std::vector<String> vStrScoreInside = StringUtil::split(*iter, ":");	// 26.0
			stOS.score = StringConverter::parseReal(vStrScoreInside[1]);
			
			std::vector<String> vStrScoreInside2 = StringUtil::split(vStrScoreInside[0], "-");	// 1-1
			stOS.start_order = StringConverter::parseUnsignedInt(vStrScoreInside2[0]);
			stOS.end_order = StringConverter::parseUnsignedInt(vStrScoreInside2[1]);
			
			stMOS.vOrderScore.push_back(stOS);
		}
		
		Log.Debug("XmlDataManager::LoadMatchOrderScoreXml","min_p[%u] max_p[%u] score size[%u]", stMOS.min_p, stMOS.max_p, stMOS.vOrderScore.size());
		m_vMarchOrderScore.push_back(stMOS);
		child = child->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadMatchOrderScoreXml","load match_order_score.xml sucess size[%i]!", m_vMarchOrderScore.size());
	return true;
}

bool XmlDataManager::ReLoadMatchOrderScoreXml(void)
{
	return LoadMatchOrderScoreXml();
}

// 获取比赛排名对应积分
float XmlDataManager::GetMatchOrderScore(const uint32 & total_player, const uint32 & order)
{
	if(total_player ==0 || order == 0)
		return 0.0f;
	
WGS_XML_READ_LOCK
	std::vector<stMatchOrderScore>::iterator iter, ei = m_vMarchOrderScore.end();
	for(iter = m_vMarchOrderScore.begin(); iter!=ei; ++iter)
	{
		if(total_player >= (*iter).min_p && total_player <= (*iter).max_p)
		{
			std::vector<stOrderScore>::iterator iter2, ei2 = (*iter).vOrderScore.end();
			for(iter2 = (*iter).vOrderScore.begin(); iter2!=ei2; ++iter2)
			{
				if(order >= (*iter2).start_order && order <= (*iter2).end_order)
				{// 找到指定名次的积分
					Log.Debug("XmlDataManager::GetMatchOrderScore","total_player[%u] order[%u] score[%f]", total_player, order, (*iter2).score);
					return (*iter2).score;
				}
			}
		}
	}
	
	return 0.0f;
}

// 加载机器人配置
bool XmlDataManager::LoadDDZRobotXml()
{
	TiXmlDocument doc("../scripts_xml/ddz/robot_config.xml");
	if(!doc.LoadFile())
	{
		Log.Error("XmlDataManager::LoadDDZRobotXml", "load robot_config.xml failed!");
		return false;
	}
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("XmlDataManager::LoadDDZRobotXml", "robot_config.xml have not root node!");
		return false;
	}
	
	m_vDDZRobot.clear();
	m_vDDZRobotName.clear();
	m_vDDZRobotIcon.clear();
	m_vDDZRobotPid.clear();
	m_vDDZRobotAddr.clear();
	while(pRoot)
	{
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			if (strcmp(pRoot->Value(), "robot_jinbi") == 0)
			{// 机器人配置
				stDDZRobot stDR;
				stDR.index = StringConverter::parseUnsignedInt(child->Attribute("index"));
				stDR.show_pid = StringConverter::parseUnsignedInt(child->Attribute("show_pid"));
				stDR.show_uid = StringConverter::parseUnsignedInt(child->Attribute("show_uid"));
				stDR.sex = StringConverter::parseUnsignedInt(child->Attribute("sex"));
				stDR.char_id = StringConverter::parseUnsignedInt(child->Attribute("char_id"));
				stDR.init_coins = StringConverter::parseUnsignedInt(child->Attribute("init_coins"));
				stDR.init_fangka = StringConverter::parseUnsignedInt(child->Attribute("init_fangka"));
				stDR.nick = child->Attribute("nick");
				stDR.icon = child->Attribute("icon");
				stDR.addr = child->Attribute("addr");
				
				m_vDDZRobot.push_back(stDR);
			}
			else if (strcmp(pRoot->Value(), "random_name") == 0)
			{// 名字库
				m_vDDZRobotName.push_back(child->Attribute("nick"));
			}
			else if (strcmp(pRoot->Value(), "random_icon") == 0)
			{// 头像库
				m_vDDZRobotIcon.push_back(child->Attribute("url"));
			}
			else if (strcmp(pRoot->Value(), "random_addr") == 0)
			{// 地址库
				m_vDDZRobotAddr.push_back(child->Attribute("addr"));
			}
			else if (strcmp(pRoot->Value(), "random_showpid") == 0)
			{// PID库
				m_vDDZRobotPid.push_back(StringConverter::parseUnsignedInt(child->Attribute("pid")));
			}
			
			child = child->NextSiblingElement();
		}
		
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("XmlDataManager::LoadDDZRobotXml:", "load robot_config.xml successfully m_vDDZRobot[%u]!", m_vDDZRobot.size());
	return true;
}

bool XmlDataManager::ReLoadDDZRobotXml()
{
	bool bRe = LoadDDZRobotXml();
	return bRe;
}
/* -------------------------扑克相关------------------------- */
// 加载扑克框架配置
bool XmlDataManager::LoadPuKePublicDataXml(void)
{
	char strPath[512] = "";
	sprintf(strPath, "%s/puke_public.xml", _GAME_XMLFILE_PATH_);
	TiXmlDocument doc(strPath);
	if(!doc.LoadFile())
	{
		Log.Error("load XML Error", "load puke_public.xml failed!");
		return false;
	}
	
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
	{
		Log.Error("load Xml Error", "puke_public.xml have not root node!");
		return false;
	}
	
WGS_XML_WRITE_LOCK

	m_mapPuKeMoreData.clear();
	while(pRoot)
	{
		uint32 ai = StringConverter::parseUnsignedInt(pRoot->Attribute("ai"));
		std::map<String, uint32> PuKeData;
		
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{	
			String name = child->Attribute("name");
			uint32 value = StringConverter::parseUnsignedInt(child->Attribute("value"));
			PuKeData.insert(std::make_pair(name,value));
			
			child = child->NextSiblingElement();
		}
		
		m_mapPuKeMoreData.insert(std::make_pair(ai, PuKeData));
		pRoot = pRoot->NextSiblingElement();
	}
	
	Log.Debug("LoadCenterBattleModeXml","Load puke_public.xml size[%u] sucess!", m_mapPuKeMoreData.size());
	return true;
}
//扑克
bool XmlDataManager::ReLoadPuKePublicDataXml(void)
{
	return LoadPuKePublicDataXml();
}

//获得扑克配置----------------------------------
uint32 	XmlDataManager::GetPuKeXMLData(const uint32 & ai, const String & str)
{
	WGS_XML_READ_LOCK
	
	std::map<uint32, std::map<String, uint32 > >::iterator pmi = m_mapPuKeMoreData.find(ai);
	if(pmi != m_mapPuKeMoreData.end())
	{
		std::map<String, uint32> m_mapPuKeData = m_mapPuKeMoreData[ai];
		
		std::map<String, uint32>::iterator mi = m_mapPuKeData.find(str);
		if(mi != m_mapPuKeData.end())
			return m_mapPuKeData[str];
	}
	
	pmi = m_mapPuKeMoreData.find(ai);
	if(pmi != m_mapPuKeMoreData.end())
	{
		std::map<String, uint32> m_mapPuKeData = m_mapPuKeMoreData[ai];
		
		std::map<String, uint32>::iterator mi = m_mapPuKeData.find(str);
		if(mi != m_mapPuKeData.end())
			return m_mapPuKeData[str];
	}
	
	return 0;
}

// 修改机器人角色ID
void XmlDataManager::SetRobotData(const uint32 & index, const uint32 & char_id, const uint32 & show_pid, const String & strAddr)
{
	Log.Debug("XmlDataManager::SetRobotCharId","index[%u] char_id[%u] 111", index, char_id);
	
	TiXmlDocument doc("../scripts_xml/ddz/robot_config.xml");
	if(!doc.LoadFile())
		return ;
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
		return ;
	
	while(pRoot)
	{
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			if (strcmp(pRoot->Value(), "robot_jinbi") == 0)
			{
				if(StringConverter::parseUnsignedInt(child->Attribute("index")) == index)
				{
					Log.Debug("XmlDataManager::SetRobotCharId","index[%u] char_id[%u] 222", index, char_id);
					child->SetAttribute("char_id", char_id);
					child->SetAttribute("show_pid", show_pid);
					child->SetAttribute("addr", strAddr.c_str());
					doc.SaveFile();
					
					std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
					for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
					{
						if((*iter).index == index)
						{
							(*iter).char_id = char_id;
							(*iter).show_pid = show_pid;
							(*iter).addr = strAddr;
							
							Log.Debug("XmlDataManager::SetRobotCharId","index[%u] char_id[%u] 333", (*iter).index, (*iter).char_id);
							break;
						}
					}
					
					break;
				}
			}
			
			child = child->NextSiblingElement();
		}
		
		pRoot = pRoot->NextSiblingElement();
	}
	
}

// 判断玩家是否在控制列表中
bool XmlDataManager::IsBankerInContrlList(const uint32 & char_id)
{
WGS_XML_WRITE_LOCK
	std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
	for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
	{
		if((*iter).char_id == char_id)
			return true;
	}
	
	return false;
}

// 获得一个随机机器人ID
uint32 XmlDataManager::getBankerInContrlCharIdRandom()
{
WGS_XML_WRITE_LOCK
	if(m_vDDZRobot.empty())
		return 0;
	
	uint32 try_count = 0;
	while(try_count++ < 100)
	{
		uint32 rand_index = RandomUInt(m_vDDZRobot.size() - 1);
		if(m_vDDZRobot[rand_index].bUsed)
			continue;
		
		return m_vDDZRobot[rand_index].char_id;
	}
	
	return 0;
}

// 设置机器人使用状态
void XmlDataManager::setRobotUsed(const uint32 & char_id, bool bUsed)
{
	if(char_id == 0)
		return ;
	
WGS_XML_WRITE_LOCK
	std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
	for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
	{
		if((*iter).char_id == char_id)
		{
			(*iter).bUsed = bUsed;
			break;
		}
	}
}

// 获得一个机器人被使用状态 默认返回true，使用中，让外部调用不使用
bool XmlDataManager::isRobotUsed(const uint32 & char_id)
{
	if(char_id == 0)
		return true;
	
WGS_XML_WRITE_LOCK
	std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
	for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
	{
		if((*iter).char_id == char_id)
		{
			return (*iter).bUsed;
		}
	}
	
	return true;
}

// 获得一个机器人的PID
uint32 XmlDataManager::getRobotShowPid(const uint32 & char_id)
{
	if(char_id == 0)
		return 0;
	
WGS_XML_WRITE_LOCK
	std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
	for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
	{
		if((*iter).char_id == char_id)
		{
			return (*iter).show_pid;
		}
	}

	return 0;
}

// 给机器人随机昵称
String XmlDataManager::randomRobotNick()
{
	uint32 try_count = 0;
	
WGS_XML_WRITE_LOCK
	if(m_vDDZRobotName.empty())
		return "";
	
	while(try_count++ < 100)
	{
		++try_count;
		String rand_name = m_vDDZRobotName[RandomUInt(0, m_vDDZRobotName.size() - 1)];
		if(rand_name == "")
			continue;
		
		bool bFindName = false;
		std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
		for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
		{
			if(!rand_name.compare((*iter).nick))
			{
				bFindName = true;
				break;
			}
		}
		
		if(!bFindName)
			return rand_name;
	}
	
	return "";
}

// 给机器人随机头像
String XmlDataManager::randomRobotIcon()
{
	uint32 try_count = 0;
	
WGS_XML_WRITE_LOCK
	if(m_vDDZRobotIcon.empty())
		return "";
	
	while(try_count++ < 100)
	{
		++try_count;
		String rand_icon = /* m_vDDZRobotIcon[RandomUInt(0, m_vDDZRobotIcon.size() - 1)] */sGLMgr.GetRandomHeadIcon(5048);
		if(rand_icon == "")
			continue;
		
		bool bFindIcon = false;
		std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
		for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
		{
			if(!rand_icon.compare((*iter).icon))
			{
				bFindIcon = true;
				break;
			}
		}
		
		if(!bFindIcon)
			return rand_icon;
	}
	
	return "";
}

// 给机器人随机显示用的PID
uint32 XmlDataManager::randomRobotPid()
{
	uint32 try_count = 0;
	
WGS_XML_WRITE_LOCK
	if(m_vDDZRobotPid.empty())
		return 0;
	
	while(try_count++ < 100)
	{
		++try_count;
		uint32 rand_pid = m_vDDZRobotPid[RandomUInt(0, m_vDDZRobotPid.size() - 1)];
		if(rand_pid == 0)
			continue;
		
		bool bFindPid = false;
		std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
		for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
		{
			if(rand_pid == (*iter).show_pid)
			{
				bFindPid = true;
				break;
			}
		}
		
		if(!bFindPid)
			return rand_pid;
	}
	
	return 0;
}

// 给机器人随机地址
String XmlDataManager::randomRobotAddr()
{
WGS_XML_WRITE_LOCK
	if(m_vDDZRobotAddr.empty())
		return "";
	
	return m_vDDZRobotAddr[RandomUInt(m_vDDZRobotAddr.size() - 1)];
}

// 设置机器人昵称头像
bool XmlDataManager::setDDZRobotNickIcon(const uint32 & index, String strNewName, String strNewIcon)
{
	TiXmlDocument doc("../scripts_xml/ddz/robot_config.xml");
	if(!doc.LoadFile())
		return false;
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
		return false;
	
	while(pRoot)
	{
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			if (strcmp(pRoot->Value(), "robot_jinbi") == 0)
			{
				if(StringConverter::parseUnsignedInt(child->Attribute("index")) == index)
				{
					child->SetAttribute("nick", strNewName.c_str());
					child->SetAttribute("icon", strNewIcon.c_str());
					doc.SaveFile();
					
					std::vector<stDDZRobot>::iterator iter, ei = m_vDDZRobot.end();
					for(iter = m_vDDZRobot.begin(); iter!=ei; ++iter)
					{
						if((*iter).index == index)
						{
							(*iter).nick = strNewName;
							(*iter).icon = strNewIcon;
							break;
						}
					}
					
					return true;
				}
			}
			
			child = child->NextSiblingElement();
		}
		
		pRoot = pRoot->NextSiblingElement();
	}
	
	return false;
}

// 机器人根据charid排序
void XmlDataManager::OrderRobotByCharid()
{
WGS_XML_WRITE_LOCK
	std::sort(m_vDDZRobot.begin(), m_vDDZRobot.end(), compareRobotCharid);
}

// 重置所有机器人昵称头像
void XmlDataManager::ResetDDZRobotNickIcon()
{
	TiXmlDocument doc("../scripts_xml/ddz/robot_config.xml");
	if(!doc.LoadFile())
		return ;
	
WGS_XML_WRITE_LOCK
	TiXmlElement* pRoot = doc.RootElement();
	if (NULL == pRoot)
		return ;
	
	while(pRoot)
	{
		TiXmlElement* child = pRoot->FirstChildElement();
		while(child)
		{
			if (strcmp(pRoot->Value(), "robot_jinbi") == 0)
			{
				child->SetAttribute("char_id", 0);
			}
			
			child = child->NextSiblingElement();
		}
		
		pRoot = pRoot->NextSiblingElement();
	}
	
	doc.SaveFile();
}
	

